Creates a scoped React context system, returning a context provider/hook pair and a scope composer to isolate context instances and avoid collisions.
/* @__NO_SIDE_EFFECTS__ */ function createContextScope(
scopeName: string,
createContextScopeDeps: CreateScope[] = [],
): readonly [CreateScopedContext, CreateScope] {
let defaultContexts: any[] = [];
/* -----------------------------------------------------------------------------------------------
* createContext
* ---------------------------------------------------------------------------------------------*/
function createContext<ContextValueType extends object | null>(
rootComponentName: string,
defaultContext?: ContextValueType,
) {
const BaseContext = React.createContext<ContextValueType | undefined>(defaultContext);
BaseContext.displayName = rootComponentName + 'Context';
const index = defaultContexts.length;
defaultContexts = [...defaultC
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key