UNPKG

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

24 lines (23 loc) 2.01 kB
import type { StateHook, StateSetter, ActionCollectionConfig, ActionCollectionResult, GlobalStoreCallbacks, CustomGlobalHookBuilderParams } from "react-hooks-global-states/types"; import type { AsyncStorageConfig, BaseMetadata } from "./types"; export interface CustomCreateGlobalState<TCustomConfig extends BaseMetadata | unknown, InheritMetadata extends BaseMetadata | unknown = BaseMetadata> { <State>(state: State): StateHook<State, StateSetter<State>, BaseMetadata>; <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, InheritMetadata & Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<State> : ActionCollectionResult<State, InheritMetadata & Metadata, NonNullable<ActionsConfig>>>(state: State, args: { name?: string; metadata?: Metadata; callbacks?: GlobalStoreCallbacks<State, InheritMetadata & Metadata>; actions?: ActionsConfig; config?: TCustomConfig; asyncStorage?: AsyncStorageConfig; }): StateHook<State, PublicStateMutator, InheritMetadata & Metadata>; <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends Readonly<ActionCollectionConfig<State, InheritMetadata & Metadata>>>(state: State, args: { name?: string; metadata?: Metadata; callbacks?: GlobalStoreCallbacks<State, InheritMetadata & Metadata>; actions: ActionsConfig; config?: TCustomConfig; asyncStorage?: AsyncStorageConfig; }): StateHook<State, ActionCollectionResult<State, InheritMetadata & Metadata, ActionsConfig>, InheritMetadata & Metadata>; } export declare const createCustomGlobalState: <TCustomConfig extends BaseMetadata | unknown, InheritMetadata extends BaseMetadata | unknown = BaseMetadata>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<TCustomConfig, InheritMetadata>) => CustomCreateGlobalState<TCustomConfig, InheritMetadata>; export default createCustomGlobalState;