Last active
December 9, 2022 16:25
-
-
Save sjednac/5903800abd244c23f25f3ea189b08503 to your computer and use it in GitHub Desktop.
React/Typescript snippets for Visual Studio Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
// Place your frlncr workspace 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: | |
"Component Typescript": { | |
"scope": "typescript,typescriptreact", | |
"prefix": "compts", | |
"body": [ | |
"import React from \"react\"", | |
"", | |
"export type ${1:ComponentName}Props = Readonly<{", | |
"}>", | |
"", | |
"export const ${1:ComponentName}: React.FC<${1:ComponentName}Props> = () => {", | |
" return (", | |
" <>", | |
" $0", | |
" </>", | |
" )", | |
"}" | |
], | |
"description": "Create a React component in Typescript" | |
}, | |
"Component Unit Test Typescript": { | |
"scope": "typescript,typescriptreact", | |
"prefix": "comptestts", | |
"body": [ | |
"import { render, screen } from \"@testing-library/react\"", | |
"import React from \"react\"", | |
"import { ${1:ComponentName} } from \"./${1:ComponentName}\"", | |
"", | |
"describe(\"${1:ComponentName}\", () => {", | |
" it(\"renders the component\", () => {", | |
" render(<${1:ComponentName} />)", | |
" $0", | |
" expect(screen.queryByText(\"foo\")).toBeInTheDocument()", | |
" })", | |
"})" | |
], | |
"description": "Create a unit test for the React component in Typescript" | |
}, | |
"Component Storybook Typescript": { | |
"scope": "typescript,typescriptreact", | |
"prefix": "compstoryts", | |
"body": [ | |
"import { ComponentStory, ComponentMeta } from \"@storybook/react\"", | |
"import React from \"react\"", | |
"import { ${1:ComponentName} } from \"./${1:ComponentName}\"", | |
"", | |
"export default {", | |
" title: \"${2:path}/${1:ComponentName}\",", | |
" component: ${1:ComponentName},", | |
"} as ComponentMeta<typeof ${1:ComponentName}>", | |
"", | |
"const Template: ComponentStory<typeof ${1:ComponentName}> = (args) => (", | |
" <${1:ComponentName} {...args} />", | |
")", | |
"", | |
"export const Default = Template.bind({})", | |
"Default.args = {}" | |
], | |
"description": "Create a Storybook for the React component in Typescript" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment