Skip to content

Instantly share code, notes, and snippets.

@TheYarin
Last active May 2, 2020 17:43
Show Gist options
  • Save TheYarin/c6b7605e9ca5c4e8fa0cfec8b5139ff1 to your computer and use it in GitHub Desktop.
Save TheYarin/c6b7605e9ca5c4e8fa0cfec8b5139ff1 to your computer and use it in GitHub Desktop.
A useful VSCode snippet that generates a React class component with all the Material-UI styling boilerplate built in.
{
// 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
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"typeScriptReactClassMuiComponent": {
"prefix": "muicts",
"body": [
"import React, { Component } from 'react'",
"import { createStyles, WithStyles, withStyles, Theme } from '@material-ui/core';",
"",
"const styles = (theme: Theme) => createStyles({",
"\troot: {",
"\t}",
"});",
"",
"interface Props extends WithStyles<typeof styles> {",
"\t",
"}",
"",
"class ${1:${TM_FILENAME_BASE}} extends Component<Props> {",
"\trender() {",
"\t\tconst { classes } = this.props;",
"",
"\t\treturn (",
"\t\t\t<div className={classes.root}>",
"\t\t\t\t$0",
"\t\t\t</div>",
"\t\t)",
"\t}",
"}",
"",
"export default withStyles(styles)(${1:${TM_FILENAME_BASE}})",
""
],
"description": "Creates a React component class with ES7 module system and TypeScript Props interface, including Material-UI styles"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment