Skip to content

Instantly share code, notes, and snippets.

@mwarger
Created August 7, 2019 17:17
Show Gist options
  • Save mwarger/c4872b48dd8adad5c2d762e1d0f4f00c to your computer and use it in GitHub Desktop.
Save mwarger/c4872b48dd8adad5c2d762e1d0f4f00c to your computer and use it in GitHub Desktop.
ts code snippets for react, ts, theme-ui
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. 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": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Functional Component": {
"scope": "typescriptreact",
"prefix": "fc",
"body": [
"export const $TM_FILENAME_BASE:React.FC = () => {\n",
" return <>$1</>",
"}"
]
},
"Functional Component With Props": {
"scope": "typescriptreact",
"prefix": "fcp",
"body": [
"export const $TM_FILENAME_BASE:React.FC<$1> = ({$2}) => {\n",
" return <>$3</>",
"}"
]
},
"Functional Component Test": {
"scope": "typescriptreact",
"prefix": "fct",
"body": [
"import React from 'react';",
"import { render } from 'utils/test-utils';",
"import { $1 } from '../$1';",
"\n",
"test('renders without crashing', () => {",
"\trender(<$1 />);",
"});"
]
},
"Functional Route Component": {
"scope": "typescriptreact",
"prefix": "fcr",
"body": [
"import { RouteComponentProps } from '@reach/router'\n",
"const $TM_FILENAME_BASE:React.FC<RouteComponentProps<{$1}>> = ({$2}) => {\n",
" return <>$3</>",
"}\n",
"export default $TM_FILENAME_BASE"
]
},
"Import * from React": {
"scope": "typescriptreact",
"prefix": "imr",
"body": "import * as React from 'react'\n"
},
"Import JSX and pragma": {
"scope": "typescriptreact",
"prefix": "imjsx",
"body": "/** @jsx jsx */\nimport { jsx } from 'theme-ui'"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment