@raulpesilva/re-state
Version:
easy way to create a shared state to the entire application
20 lines (19 loc) • 1.29 kB
TypeScript
import { SetReStateAction } from '../core';
import { DispatchReState } from './types';
declare type useReState<S extends string, V> = Record<`use${Capitalize<S>}`, () => [V, DispatchReState<SetReStateAction<V>>]>;
declare type useReStateSelect<S extends string, V> = Record<`use${Capitalize<S>}Select`, () => V>;
declare type dispatchReState<S extends string, V> = Record<`dispatch${Capitalize<S>}`, DispatchReState<SetReStateAction<V>>>;
declare type getReState<S extends string, V> = Record<`get${Capitalize<S>}`, () => V>;
declare type resetReState<S extends string> = Record<`reset${Capitalize<S>}`, () => void>;
declare type ReStateMethods<T extends string, S> = useReState<T, S> & useReStateSelect<T, S> & dispatchReState<T, S> & getReState<T, S> & resetReState<T>;
/**
* Creates a set of methods to use with React.
* @param name Unique name of the state
* @param initialValue initial value of the state
* @param valueOfReset value to reset when calling resetReState
* @returns a set of methods to use with React
*/
export declare const createReStateMethods: <S extends string = string, V extends unknown = any>(name: S, initialValue?: V | undefined, valueOfReset?: {
value: V;
} | undefined) => { [K in keyof ReStateMethods<S, V>]: ReStateMethods<S, V>[K]; };
export {};