UNPKG

zustand-utils

Version:
29 lines (28 loc) 952 B
import type { ReactNode } from 'react'; import type { StoreApi } from 'zustand'; export type UseContextStore<S extends StoreApi<unknown>> = { (): ExtractState<S>; <U>(selector: (state: ExtractState<S>) => U, equalityFn?: (a: U, b: U) => boolean): U; }; type ExtractState<S> = S extends { getState: () => infer T; } ? T : never; type WithoutCallSignature<T> = { [K in keyof T]: T[K]; }; interface CreateContextParams { equalityFn?: <U>(a: U, b: U) => boolean; } /** * create context for individual App * mostly use for component */ export declare const createContext: <S extends StoreApi<unknown>>(params?: CreateContextParams) => { Provider: ({ createStore, children }: { createStore: () => S; children: ReactNode; }) => import("react").FunctionComponentElement<import("react").ProviderProps<S | undefined>>; useStore: UseContextStore<S>; useStoreApi: () => WithoutCallSignature<S>; }; export {};