Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm functional snippet React

Does anybody knows what the shortcut is for React functional components snippet in WebStorm?

So far I only found shortcut for class components.

like image 801
Andres Diaz Avatar asked Aug 04 '20 03:08

Andres Diaz


People also ask

Is WebStorm good for React?

WebStorm provides code completion for React APIs and JSX in JavaScript code. Code completion works for React methods, React-specific attributes, HTML tags and component names, React events, component properties, and so on. Learn more from the React official website.

How do I get React snippets in Intellij?

React code snippetsPress Ctrl+J and choose the relevant snippet.


2 Answers

Please try rsf - it creates a code like

import React from 'react';

function Func(props) {
  return (<div></div>);
}

export default Func;

enter image description here

like image 128
lena Avatar answered Sep 22 '22 08:09

lena


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:

  • statement
  • top level statement
like image 22
Phil O. Avatar answered Sep 21 '22 08:09

Phil O.