Skip to content

Instantly share code, notes, and snippets.

@rittme
Created June 19, 2023 02:49
Show Gist options
  • Save rittme/662625d339a279bc365d9c2a837b0e64 to your computer and use it in GitHub Desktop.
Save rittme/662625d339a279bc365d9c2a837b0e64 to your computer and use it in GitHub Desktop.
VS Code snippet: React Context
{
"React Context": {
"scope": "javascript,typescript",
"isFileTemplate": true,
"prefix": "context",
"body": [
"import React, { createContext, useContext } from 'react';",
"",
"const ${1:Data}Context = createContext(null);",
"",
"export const ${1:Data}Provider = ({",
" children,",
"}) => {",
"",
" const value = {",
" $0",
" };",
" return <${1:Data}Context.Provider value={value}>{children}</${1:Data}Context.Provider>;",
"};",
"",
"export const use${1:Data} = () => {",
" return useContext(${1:Data}Context);",
"};",
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment