react-native-global-state-hooks
Version:
This is a package to easily handling global-state across your react-native-components No-redux... The library now includes @react-native-async-storage/async-storage to persist your state across sessions... if you want to keep using the old version without
32 lines (31 loc) • 1.8 kB
TypeScript
import type { ActionCollectionConfig, GlobalStoreCallbacks, StateChanges } from "react-hooks-global-states/types";
import type { ActionCollectionResult, AsyncStorageConfig, BaseMetadata, AsyncMetadata, AnyFunction } from "./types";
import GlobalStoreBase from "react-hooks-global-states/GlobalStore";
/**
* React Native Global Store with Async Storage support
*/
export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | undefined | unknown, PublicStateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>> extends GlobalStoreBase<State, AsyncMetadata<Metadata>, ActionsConfig> {
asyncStorage: AsyncStorageConfig<State> | null;
constructor(state: State);
constructor(state: State, args: {
metadata?: Metadata;
callbacks?: GlobalStoreCallbacks<State, PublicStateMutator extends AnyFunction ? null : PublicStateMutator, Metadata>;
actions?: ActionsConfig;
name?: string;
asyncStorage?: AsyncStorageConfig<State>;
});
getMetadata: () => AsyncMetadata<Metadata>;
protected isPersistStorageAvailable: () => boolean;
private trySetStorageItem;
private updateStateWithValidation;
/**
* Instead of calling onInitialize and onChange directly, we call the _onInitialize and _onChange
* This allows the concat the logic of the GlobalStore with the logic of the extension class.
*/
protected onInit: () => Promise<void>;
protected onStateChanged: (changes: StateChanges<State>) => Promise<void>;
private getStorageItem;
private setStorageItem;
private handleStorageError;
}
export default GlobalStore;