zustore
Version:
A lightweight global state management library for React built on contextApi.
41 lines (40 loc) • 1.73 kB
TypeScript
import React, { ReactNode } from "react";
type apiFunctionType = ({ state, addState, dispatch, }: {
state: Record<string, any>;
dispatch: (newState: Record<string, any>, key?: string) => void;
addState: (newState: Record<string, any>, key?: string) => void;
}) => any;
export declare const CreateDispatch: (handler: ({ name, payload, tools, }: {
name: string;
payload: any;
tools: Tools;
}) => void) => CreateDispatchType;
type InitialState = Record<string, any>;
type CreateDispatchType = (args: {
name: string;
payload: any;
tools: Tools;
}) => void;
interface Tools {
dispatch: (newState: Record<string, any>, key?: string) => void;
addState: (newState: Record<string, any>, key?: string) => void;
reset: (keys: string | string[]) => void;
dirty: (keys: string | string[]) => void;
state: Record<string, any>;
}
export declare const useDispatch: () => {
state: Record<string, any>;
dispatcher: (functionName: string, payload?: any) => void;
addState: (newState: Record<string, any>, key?: string) => void;
dispatch: (newState: Record<string, any>, key?: string) => void;
reset: (keys: string | string[]) => void;
dirty: (keys: string | string[]) => void;
ApiCall: (apiFunction: apiFunctionType) => void;
};
export declare function useSelector<T = any>(selector: string, defaultValues?: T): T;
export declare function useSelector<T = any>(selector: string[], defaultValues?: T[]): T;
export declare function useSelector<T = any>(selector: (state: Record<string, any>) => T, defaultValues?: T): T;
export declare const initial: (initialState: InitialState, createDispatch?: CreateDispatchType) => React.FC<{
children: ReactNode;
}>;
export {};