@nebula-note/redux-hooks
Version:
Simplify Redux usage: no actions, no reducers, only hooks.
35 lines (27 loc) • 1.62 kB
TypeScript
import { ConfigureStoreOptions } from '@reduxjs/toolkit';
import { EnhancedStore } from '@reduxjs/toolkit';
import { Reducer } from '@reduxjs/toolkit';
export declare const configureStore: <State = Record<string, unknown>>(options?: ConfigureStoreOptions<State>) => Store<State>;
export declare const getStore: () => Store<any> | undefined;
declare interface ReducerManager<State> {
getReducerMap: () => Record<string, Reducer>;
reduce: (state: State | undefined, action: any) => State;
add: (key: string, reducer: Reducer) => void;
remove: (key: string) => void;
}
declare type SliceUpdater<StateType> = (ownState: StateType) => StateType;
declare interface Store<State> extends EnhancedStore<State> {
reducerManager: ReducerManager<State>;
addTaker: (actionType: string, callback: () => void) => () => void;
}
export declare const useRedux: <SliceType>(stateName: string, initialState: SliceType) => {
readonly state: SliceType;
readonly getStateSync: () => SliceType;
readonly setState: (payload: SliceType | SliceUpdater<SliceType>) => void;
readonly setStateSync: (payload: SliceType | SliceUpdater<SliceType>) => void;
readonly updateState: <T extends typeof initialState>(payload: { [K in keyof T]?: Partial<T[K]>; }) => void;
readonly updateStateSync: <T extends typeof initialState>(payload: { [K in keyof T]?: Partial<T[K]>; }) => void;
readonly take: (actionType: "setState" | "updateState") => Promise<() => void>;
readonly takeOnce: (actionType: "setState" | "updateState") => Promise<void>;
};
export { }