@liuyunjs/constate
Version:
Yet another React state management library that lets you work with local state and scale up to global state with ease
16 lines (15 loc) • 874 B
TypeScript
import * as React from 'react';
declare type Selector<Value> = (value: Value) => any;
declare type SelectorHooks<Selectors> = {
[K in keyof Selectors]: () => Selectors[K] extends (...args: any) => infer R ? R : never;
};
declare type Provider<Props, Value> = React.FC<Props> & {
useProvider: (props?: Props) => [(element: React.ReactNode) => React.ReactElement, Value];
};
declare type Hooks<Value, Selectors extends Selector<Value>[]> = Selectors['length'] extends 0 ? [() => Value] : SelectorHooks<Selectors>;
declare type ConstateTuple<Props, Value, Selectors extends Selector<Value>[]> = [
Provider<Props, Value>,
...Hooks<Value, Selectors>
];
export declare function constate<Props, Value, Selectors extends Selector<Value>[]>(useValue: (props: Props) => Value, ...selectors: Selectors): ConstateTuple<Props, Value, Selectors>;
export default constate;