It would be awesome if we had the option to create context modules that export providers and hooks. I think most of the time, these files are boilerplates.
Input: ContextName
Produces:
- a folder called
<ContextName>Context
- index file
<ContextName>Context.tsx
export * from './__ContextName__Context';
// <ContextName>Context.tsx
import React, { createContext, useContext } from 'react';
export interface __ContextName__Value {
}
const context = createContext<__ContextName__Value | null>(null);
export function __ContextName__Provider({ children }: __ContextName__Value & { children: React.ReactNode }) {
return (
<context.Provider value={{ }}>
{children}
</context.Provider>
);
}
export function use__ContextName__(): __ContextName__Value {
const value = useContext(context);
if (!value) {
throw new Error('use__ContextName__ must be used within a __ContextName__Provider');
}
return value;
}
It would be awesome if we had the option to create context modules that export providers and hooks. I think most of the time, these files are boilerplates.
Input: ContextName
Produces:
<ContextName>Context<ContextName>Context.tsx