UNPKG

react-global-state-hooks

Version:

This is a package to easily handling global-state across your react components

24 lines (23 loc) 1.54 kB
import type { ActionCollectionConfig, ActionCollectionResult, AnyFunction, BaseMetadata, GlobalStoreCallbacks, StateChanges } from 'react-hooks-global-states/types'; import GlobalStoreBase from 'react-hooks-global-states/GlobalStore'; import type { LocalStorageConfig, ItemEnvelope } from './types'; 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, Metadata, ActionsConfig> { protected localStorage: LocalStorageConfig<State> | null; constructor(state: State); constructor(state: State, args: { metadata?: Metadata; callbacks?: GlobalStoreCallbacks<State, PublicStateMutator extends AnyFunction ? null : PublicStateMutator, Metadata>; actions?: ActionsConfig; name?: string; localStorage?: LocalStorageConfig<State>; }); protected isPersistStorageAvailable: () => boolean; protected onInit: () => void; trySetStorageItem: (state: State) => void; updateStateWithValidation: (state: State) => void; protected onStateChanged: ({ state }: StateChanges<State>) => void; getStorageItem: () => ItemEnvelope<State> | null; setStorageItem: (state: State) => void; handleStorageError: (error: unknown) => void; } export default GlobalStore;