Skip to content

Instantly share code, notes, and snippets.

@celian-rib
Last active July 20, 2023 04:11
Show Gist options
  • Save celian-rib/ea6e723cfbaec5fd5f9183d142380c5e to your computer and use it in GitHub Desktop.
Save celian-rib/ea6e723cfbaec5fd5f9183d142380c5e to your computer and use it in GitHub Desktop.
React Context Provider template with TypeScript
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