Skip to content

Instantly share code, notes, and snippets.

@adbutterfield
Last active June 3, 2020 06:47
Show Gist options
  • Save adbutterfield/618cd5c92abf277cc0b7b71c93e3fb0e to your computer and use it in GitHub Desktop.
Save adbutterfield/618cd5c92abf277cc0b7b71c93e3fb0e to your computer and use it in GitHub Desktop.
Snippits for vscode
{
// 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"
// }
"Stub context": {
"prefix": "cntx",
"body": [
"import React, { createContext, useReducer } from 'react';\n",
"type $1ContextArgs = {",
"\tstate: $1ContextState;",
"\tdispatch: React.Dispatch<$1ContextAction>;",
"};\n",
"type $1ContextState = {",
"};\n",
"type $1ContextAction = {",
"\ttype: string;",
"\tpayload: { };",
"};\n",
"const $1Reducer = (state: $1ContextState, action: $1ContextAction) => {",
"\tswitch (action.type) {",
"\t\tcase 'SET':",
"\t\t\treturn {",
"\t\t\t};",
"\t\tdefault:",
"\t\t\treturn state;",
"\t}",
"};\n",
"const $1Context = createContext({} as $1ContextArgs);",
"const initialState = {",
"};\n",
"export const $1ContextProvider: React.FC = ({ children }) => {",
"\tconst [state, dispatch] = useReducer($1Reducer, initialState);",
"\tconst value = { state, dispatch };",
"\t$1Context.displayName = '$1Context';",
"\treturn (",
"\t\t<$1Context.Provider value={value}>{children}</$1Context.Provider>",
"\t);",
"};\n",
"export default $1Context;\n",
],
"description": "Stub context"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment