Creating components is a really time-consuming task.
To tackle this, I have created some VSCode Snnippets.
To goal is to create new snippets during the development and to share them here! 💪
- Go to
Preferences > User Snippets
- Select
JavaScript React (Babel)
- Add snippets you wants in the
JSON
file. - That's it !
- Create a new
.js
file - Write the (a part of the)
prefix
of a snippet (e.g. ForRClassComp
, you can typercc
orrclc
) - You will see your Snippet in IntelliSense.
- Press
Enter
- Enjoy your time saving 🤗.
{
"RFonctionnalComponent": {
"prefix": "RFoncComp",
"body": [
"// @flow",
"",
"import React from 'react';",
"import type { Node } from 'react';",
"import { withStyles } from 'material-ui/styles';",
"",
"type Props = {",
"\tclasses: Object,",
"};",
"",
"const ${1:Component} = ({ classes }: Props): Node => (",
"\t$2",
");",
"",
"${1:Component}.defaultProps = {};",
"",
"const styles = {};",
"",
"export default withStyles(styles)(${1:Component});",
""
],
"description": "React Fonctionnal Componnent (with Flow)"
}
}
{
"RClassComponent": {
"prefix": "RClassComp",
"body": [
"// @flow",
"",
"import React from 'react';",
"import { withStyles } from 'material-ui/styles';",
"",
"type Props = {",
"\tclasses: Object,",
"};",
"",
"type State = {};",
"",
"class ${1:Component} extends React.Component<Props, State> {",
"\tstatic defaultProps = {}",
"\trender() {",
"\t\treturn (",
"\t\t\t$2",
"\t\t);",
"\t}",
"}",
"",
"const styles = {}",
"",
"export default withStyles(styles)(${1:Component});",
""
],
"description": "React Class Componnent (with Flow)"
}
}
{
"RConstructor": {
"prefix": "RContructor",
"body": ["constructor(props) {", "\tsuper(props);", "\t$1", "}", ""],
"description": "React class component constructor"
}
}