Does anybody knows what the shortcut is for React functional components snippet in WebStorm?
So far I only found shortcut for class components.
Does anybody knows what the shortcut is for React functional components snippet in WebStorm?
So far I only found shortcut for class components.
Please try rsf
- it creates a code like
import React from 'react';
function Func(props) {
return (<div></div>);
}
export default Func;
I use the rsc
live template a lot for new components.
This creates code like:
import React from 'react';
const MyComponent = () => {
return (
<div>
</div>
);
};
export default MyComponent;
Apart from that I created my own live template in the JavaScript category for creating arrow functions to save even more time, which creates code like:
const myFunction = () => {
};
Just add a new Live Template under the JavaScript category with this template text:
const $1$ = () => {
$END$
};
And make sure to set applicable in
to JavaScript and TypeScript
and select the checkboxes for:
i. rsf
- Creates a stateless React component as a named function without PropTypes.
import React from 'react';
function AppComponent(props) {
return (
<div></div>
);
}
export default AppComponent;
ii. rsfp
- Creates a stateless React component as a named function with PropTypes.
import React from 'react';
import PropTypes from 'prop-types';
AppComponent.propTypes = {
};
function AppComponent(props) {
return (
<div></div>
);
}
export default AppComponent;
You can configure your own templates in the web-storm by your own key word
go to settings -> editor -> live templates
React
, on the right side press the add button
or alt + insert
to create a new template key bindings are based on Linux systemrafce
, description is optionalExample:
// Created on $DATE$ by $USER$: for project $project$
import React from 'react'
const $FileName$ = () => {
return (
<div>$FileName$</div>
)
}
export default $FileName$
${var_name}$ can be used to describe a inbuilt function on the ide or your custom variable
for more reference refer the webstorm documentation on inbuilt functions for live templates webstorm live templates