context-state
Version:
Like unstated-next, but Pro
25 lines (22 loc) • 891 B
text/typescript
import * as react from 'react';
import { PropsWithChildren } from 'react';
import { UseHookType, EqualityFn, Middleware, SelectorFn } from './types.mjs';
declare function createStore<Value, InitialValue>(useHook: UseHookType<InitialValue, Value>, options?: {
/**
* @description Same as React.memo's second argument
* Compare the current and next state to determine whether an update should be re-rendered
* @default shallowEqual
*/
eq?: EqualityFn;
/**
* @description Middleware for store
*/
middlewares?: Middleware<Value>[];
}): {
useStore: {
<Selected extends keyof Value>(selector?: Selected[]): Pick<Value, Selected>;
<Selected>(selector?: SelectorFn<Value, Selected>, eqFn?: EqualityFn<Selected>): Selected;
};
Provider: react.NamedExoticComponent<PropsWithChildren<InitialValue>>;
};
export { createStore };