Created
June 19, 2023 02:49
-
-
Save rittme/662625d339a279bc365d9c2a837b0e64 to your computer and use it in GitHub Desktop.
VS Code snippet: React Context
This file contains 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
{ | |
"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