Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code functional snippet React

Does anybody knows what's the shortcut for React functional components snippet in Visual Studio? I have the ES7 React/Redux/GraphQL/React-Native snippets extension enabled in the editor.

like image 331
Sergey Kirillov Avatar asked Dec 10 '25 06:12

Sergey Kirillov


2 Answers

If you wish to create React functional component snippet in VS Code follow these steps.

  1. Go to File - Preferences - Configure User Snippets
  2. Dropdown will appear. Select New Global Snippets file and type <any-name> you want and hit enter
  3. File should be created with the following name <any-name>.code-snippet
  4. Paste this code. Anything you type in prefix will be your component trigger
{
  "React Functional Component": {
    "prefix": "rfc",
    "body": [
      "import React from \"react\"",
      "",
      "const ${1:name} = (props) => {",
      "  return (",
      "    <div>",
      "      $2",
      "    </div>",
      "  )",
      "};",
      "",
      "export default ${1:name};",
      ""
    ],
    "description": "React Functional Component"
  }
}
  1. Save the file
  2. Type (in this case) rfc and hit enter.
like image 146
Krzysztof Podmokły Avatar answered Dec 11 '25 18:12

Krzysztof Podmokły


I used the rafce live template for new components.

This creates code like:

import React from 'react';

const MyComponent = () => {
    return (
        <div>
        
        </div>
    );
};

export default MyComponent;
like image 32
Sergey Kirillov Avatar answered Dec 11 '25 20:12

Sergey Kirillov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!