Skip to content

Instantly share code, notes, and snippets.

@rdgomt
Last active December 16, 2023 15:11
Show Gist options
  • Save rdgomt/f605cb2c030f7ec1d7425708beb91eca to your computer and use it in GitHub Desktop.
Save rdgomt/f605cb2c030f7ec1d7425708beb91eca to your computer and use it in GitHub Desktop.
vscode snippets
/* prettier-ignore */
// 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.
{
"snippets: console.log()": {
"prefix": "log",
"description": "Log output to console",
"body": [
"console.log('$1', $1)"
],
},
"snippets: describe": {
"prefix": "describe",
"description": "Create a describe function",
"body": [
"describe('$1', () => {",
" $0",
"})",
"",
],
},
"snippets: it": {
"prefix": "it",
"description": "Create a test function",
"body": [
"it('$1', async () => {",
" $0",
"})",
],
},
"snippets: rfc": {
"prefix": "rfc",
"description": "Create a React Functional Component",
"body": [
"export type $1Props = {",
" $0",
"}",
"",
"export function $1({ }: $1Props) {",
" return <></>",
"}",
"",
],
},
"snippets: context": {
"prefix": "context",
"description": "Create a React Context with Provider and Hook",
"body": [
"import { PropsWithChildren, createContext, useContext, useMemo } from 'react'",
"",
"export type $1ContextValue = {",
" $0",
"}",
"",
"export const $1Context = createContext({} as $1ContextValue)",
"",
"export type $1ProviderProps = PropsWithChildren<{",
"",
"}>",
"",
"export function $1Provider({ children }: $1ProviderProps) {",
" const value = useMemo(() => {",
" return {}",
" }, [])",
"",
" return <$1Context.Provider value={value}>{children}</$1Context.Provider>",
"}",
"",
"export function use$1() {",
" return useContext($1Context)",
"}",
"",
],
},
"snippets: delay": {
"prefix": "delay",
"description": "Create a promise which resolves after given time",
"body": [
"await new Promise((resolve) => {",
" setTimeout(() => {",
" resolve(null)",
" }, $0)",
"})",
],
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment