react-native-shared-state
Version:
Create shared states that can be connected to multiple react native components, allowing for simple global state management.
31 lines (30 loc) • 1.26 kB
TypeScript
/// <reference types="react" />
import { State, StorageOptions, UpdateKeys } from '../types';
declare type StateOptions = {
debugLabel?: string;
};
export declare class SharedState<S extends State> {
private debugLabel;
private componentRegister;
private eventRegister;
private stateCache;
private storageHandler;
constructor(defaultState: S, options?: StateOptions);
get state(): S;
set state(object: S);
get prevState(): Partial<S>;
set prevState(object: Partial<S>);
setState(partialState: Partial<S>, callback?: () => void): void;
refresh(callback?: () => void): void;
reset(resetData?: S, callback?: () => void): void;
register(component: React.Component, updateKeys: UpdateKeys<S>): void;
unregister(component: React.Component): void;
addListener(trigger: keyof S | (keyof S)[], callback: (current: S, prev: Partial<S>) => void): () => boolean;
useState(updateKey: UpdateKeys<S>): [S, (partialState: Partial<S>, callback?: () => void) => void];
initializeStorage(options: StorageOptions): Promise<boolean>;
useStorage(options: StorageOptions, callback?: () => void): void;
save(): Promise<boolean>;
debugger(...log: any[]): void;
toString(): string;
}
export {};