foxact
Version:
React Hooks/Utils done right. For browser, SSR, and React Server Components.
28 lines (25 loc) • 988 B
TypeScript
import { Foxact } from '../types/index.js';
interface ProviderProps<T> {
initialState?: T | (() => T);
}
/** @see https://foxact.skk.moe/context-state */
declare function createContextState<T>(initialState: T): [
Provider: React.ComponentType<Foxact.PropsWithChildren>,
useValue: () => T,
useSetValue: () => React.Dispatch<React.SetStateAction<T>>,
StateContext: React.Context<T>
];
declare function createContextState<T>(initialState: T): [
Provider: React.ComponentType<Foxact.PropsWithChildren<ProviderProps<T>>>,
useValue: () => T,
useSetValue: () => React.Dispatch<React.SetStateAction<T>>,
StateContext: React.Context<T>
];
declare function createContextState<T>(): [
Provider: React.ComponentType<Foxact.PropsWithChildren<Required<ProviderProps<T>>>>,
useValue: () => T,
useSetValue: () => React.Dispatch<React.SetStateAction<T>>,
StateContext: React.Context<T>
];
export { createContextState };
export type { ProviderProps };