0
0
JRJose Romero
nextcontextproviderβ’β’β’
Next TypeScript recipesThe code creates a context and a function that takes a context as an argument. The context defines the global scope for the function. The function uses the context to access the value of the val variable.
Library: next
Shortcut: next.context.provider.hook.create
import { createContext, useContext } from 'react';
export type Context = {
}
export const filename = createContext<Context>({ });
export function usefilename() {
return useContext(filename);
}
export const filenameProvider = ({ children }) => {
return (
<filename.Provider
value={{}}
>
{children}
</filename.Provider>
);
};
export const usefilename = () => {
const { val } = useContext(filename);
return { val };
};