React snippets(live templates) for JetBrains series editors (e.g. WebStorm, PHPStorm, IntelliJ IDEA, etc.), stolen from sublime-react and phpstorm-reactjs.
- Download
settings.jar; - Click
File->Importing Settings...on your IDE menu, selectsettings.jar, then clickOK.
- Download(save as...) and copy the
jetbrains/templates/ReactJS.xmlfile to your templates folder:
- Windows:
<your home directory>\.<product name><version number>\config\templates - Linux:
~\.<product name><version number>\config\templates - OS X:
~/Library/Preferences/<product name><version number>/templates
e.g. ~/Library/Preferences/WebStorm10/templates on OS X for WebStorm 10
Restart your IDE.
To see all templates, go to
Preferences->Live Templatesand expand theReactJSTemplate Group.
It's hard to remember shortcuts when there are a large number of options. A more efficient way is to take advantage of editor's Insert Live Template shortcut. Press Cmd + J and type as many letters as you want to filter the results.
For example, to create a new React class, type rcc and press Tab or press Cmd + J and write rcc or React.
The WebStorm official blog post:
Tips:
Documentation of available snippets:
importReact,{Component}from'react';importPropTypesfrom'prop-types';class$COMPONENT$extendsComponent{staticdefaultProps={
$START$
};staticpropTypes={};state={};render(){return(<div>$END$</div>);}}exportdefault$COMPONENT$;importReact,{PureComponent}from'react';importPropTypesfrom'prop-types';class$COMPONENT$extendsPureComponent{staticdefaultProps={
$START$
};staticpropTypes={};render(){return(<div>$END$</div>);}}exportdefault$COMPONENT$;importReactfrom'react';importPropTypesfrom'prop-types';function$COMPONENT$($PARAMETER$){return(<div>$END$</div>);}$COMPONENT$.propTypes={};$COMPONENT$.defaultProps={};exportdefault$COMPONENT$;'use strict';varReact=require('react');varPropTypes=require('prop-types');function$COMPONENT$($PARAMETER$){return(<div>$END$</div>);}$COMPONENT$.propTypes={};$COMPONENT$.defaultProps={};module.exports=$COMPONENT$;importReactfrom'react';importPropTypesfrom'prop-types';const$COMPONENT$=($PARAMETER$)=>{return(<div>$END$</div>);};$COMPONENT$.propTypes={};$COMPONENT$.defaultProps={};exportdefault$COMPONENT$;importReactfrom'react';importcreateReactClassfrom'create-react-class';importPropTypesfrom'prop-types';const$COMPONENT$=createReactClass({render(){return(<div>$END$</div>);}});exportdefault$COMPONENT$;'use strict';varReact=require('react');varcreateReactClass=require('create-react-class');varPropTypes=require('prop-types');var$COMPONENT$=createReactClass({render: function(){return(<div>$END$</div>);}});module.exports=$COMPONENT$;importReactDOMfrom'react-dom';$END$varReactDOM=require('react-dom');$END$$START$=createReactClass({render(){return($END$);}});$START$=createReactClass({render: function(){return($END$);}});componentDidMount(){$END$}componentDidMount: function(){$END$},componentDidUpdate(prevProps,prevState){$END$}componentDidUpdate: function(prevProps,prevState){$END$},componentWillMount(){$END$}componentWillMount: function(){$END$},UNSAFE_componentWillMount(){$END$}UNSAFE_componentWillMount: function(){$END$},componentWillReceiveProps(nextProps){$END$}componentWillReceiveProps: function(nextProps){$END$},UNSAFE_componentWillReceiveProps(nextProps){$END$}UNSAFE_componentWillReceiveProps: function(nextProps){$END$},UNSAFE_componentWillUpdate(nextProps,nextState){$END$}UNSAFE_componentWillUpdate: function(nextProps,nextState){$END$},componentWillUpdate(nextProps,nextState){$END$}componentWillUpdate: function(nextProps,nextState){$END$},componentWillUnmount(){$END$}componentWillUnmount: function(){$END$},getSnapshotBeforeUpdate(prevProps,prevState){$END$}getSnapshotBeforeUpdate: function(prevProps,prevState){$END$},componentDidCatch(){$END$}componentDidCatch: function(){$END$},displayName: '$END$',$START$.displayName='$END$';findDOMNode($END$);ReactDOM.findDOMNode($END$);ReactDOM.createPortal($START$,$END$);ReactDOM.hydrate($START$,$END$);ReactDOM.unmountComponentAtNode($END$);forceUpdate($END$);getDefaultProps(){return{
$END$
};}getDefaultProps: function(){return{
$END$
};},getInitialState(){return{$START$: $END$};}getInitialState: function(){return{$START$: $END$};},isMounted()this.propsconst{ $END$ }=this.props;dangerouslySetInnerHTML={{__html: '$END$'}}propTypes: {$START$: PropTypes.$END$,},$START$: PropTypes.$END$,this.refs.$END$render(){return(<div>$END$</div>);}render: function(){return(<div>$END$</div>);}shouldComponentUpdate(nextProps,nextState){$END$}shouldComponentUpdate: function(nextProps,nextState){$END$},this.setState({$START$: $END$,});this.setState((prevState)=>{return$END$;});;this.state.$END$const{ $END$ }=this.state;contextTypes: {$START$: PropTypes.$END$,},childContextTypes: {$START$: PropTypes.$END$,},this.context.$END$getChildContext(){return{$START$: $END$};}getChildContext: function(){return{$START$: $END$};},state={$START$: $END$,},staticdisplayName='$END$';staticpropTypes={$START$: PropTypes.$END$,};staticdefaultProps={$START$: $END$,};staticcontextTypes={$START$: PropTypes.$END$,};staticchildContextTypes={$START$: PropTypes.$END$,};staticgetDerivedStateFromProps(nextProps,prevState){$END$},constructor(props$START$){super(props$END$);}transitionName="$END$"transitionAppear={$END$}transitionEnter={$END$}transitionLeave={$END$}transitionEnterTimeout={$END$}transitionLeaveTimeout={$END$}transitionAppearTimeout={$END$}importReactDOMServerfrom'react-dom/server';$END$varReactDOMServer=require('react-dom/server');$END$ReactDOMServer.renderToString($END$);ReactDOMServer.renderToString($END$);ReactDOMServer.renderToNodeStream($END$);ReactDOMServer.renderToStaticNodeStream($END$);<React.StrictMode>
$END$
</React.StrictMode><React.Fragment>
$END$
</React.Fragment><>
$END$
</>React.createRef();React.forwardRef((props,ref)=>{return$END$;});const{ Provider, Consumer }=React.createContext($END$);<Providervalue={$START$}>
$END$
</Provider><Consumer>{value=>$END$}</Consumer>onCopy={$END$}onCut={$END$}onPaste={$END$}onCompositionEnd={$END$}onCompositionStart={$END$}onCompositionUpdate={$END$}onKeyDown={$END$}onKeyPress={$END$}onKeyUp={$END$}onFocus={$END$}onBlur={$END$}onChange={$END$}onInput={$END$}onSubmit={$END$}onClick={$END$}onContextMenu={$END$}onDoubleClick={$END$}onDrag={$END$}onDragEnd={$END$}onDragEnter={$END$}onDragExit={$END$}onDragLeave={$END$}onDragOver={$END$}onDragStart={$END$}onDrop={$END$}onMouseDown={$END$}onMouseEnter={$END$}onMouseLeave={$END$}onMouseMove={$END$}onMouseOut={$END$}onMouseOver={$END$}onMouseUp={$END$}onSelect={$END$}onTouchCancel={$END$}onTouchEnd={$END$}onTouchMove={$END$}onTouchStart={$END$}onScroll={$END$}onWheel={$END$}onAbort={$END$}onCanPlay={$END$}onCanPlayThrough={$END$}onDurationChange={$END$}onEmptied={$END$}onEncrypted={$END$}onEnded={$END$}onLoadedData={$END$}onLoadedMetadata={$END$}onLoadStart={$END$}onPause={$END$}onPlay={$END$}onPlaying={$END$}onProgress={$END$}onRateChange={$END$}onSeeked={$END$}onSeeking={$END$}onStalled={$END$}onSuspend={$END$}onTimeUpdate={$END$}onVolumeChange={$END$}onWaiting={$END$}onLoad={$END$}onError={$END$}onAnimationStart={$END$}onAnimationEnd={$END$}onAnimationIteration={$END$}onTransitionEnd={$END$}