Last active
July 20, 2023 04:11
-
-
Save celian-rib/ea6e723cfbaec5fd5f9183d142380c5e to your computer and use it in GitHub Desktop.
React Context Provider template with TypeScript
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
import React, { | |
createContext, useContext | |
} from 'react'; | |
interface MyContextProps { | |
attribute: unknown, | |
} | |
const MyContext = createContext<MyContextProps>({} as MyContextProps); | |
const useMyContext = (): MyContextProps => { | |
return useContext(MyContext); | |
}; | |
export default useMyContext; | |
export const MyProvider = ({ children }: { children: JSX.Element }) => { | |
return ( | |
<MyContext.Provider value={{ attribute: {} }}> | |
{children} | |
</MyContext.Provider> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment