Skip to content

Instantly share code, notes, and snippets.

@juanpablocs
Last active April 11, 2018 15:36
Show Gist options
  • Save juanpablocs/c23a05f23ad56ea7c21f0a6529fc6d48 to your computer and use it in GitHub Desktop.
Save juanpablocs/c23a05f23ad56ea7c21f0a6529fc6d48 to your computer and use it in GitHub Desktop.
Snippet for create component react ts for visual studio code.

List snippet available

typing the prefix name and pressing tab will create the code base.

Snippet React ts component function

{
  // Place your snippets for typescriptreact here. Each snippet is defined under a snippet name and has a prefix, body and 
  // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
  // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
  "Create Component Function": {
    "prefix": "ccf",
    "body": [
      "import * as React from 'react';",
      "import * as PropTypes from 'prop-types';",
      "interface Props {",
      "    ${1:VarName}?:string",
      "}",
      "const ${2:ComponentName}: React.SFC<Props> = ({ ${1:VarName} }) => (",
      "     <div>{${1:VarName}}</div>",
      ");",
      "${2:ComponentName}.propTypes = {",
      "     ${1:VarName}: PropTypes.string",
      "};",
      "export { ${2:ComponentName} };"
    ],
    "description": "React Component Typescript Presentational"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment