constate
Version:
Yet another React state management library that lets you work with local state and scale up to global state with ease
13 lines (12 loc) • 729 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 Hooks<Value, Selectors extends Selector<Value>[]> = Selectors["length"] extends 0 ? [() => Value] : SelectorHooks<Selectors>;
declare type ConstateTuple<Props, Value, Selectors extends Selector<Value>[]> = [
React.FC<React.PropsWithChildren<Props>>,
...Hooks<Value, Selectors>
];
declare function constate<Props, Value, Selectors extends Selector<Value>[]>(useValue: (props: Props) => Value, ...selectors: Selectors): ConstateTuple<Props, Value, Selectors>;
export default constate;