Skip to main content

getGlobalState()

import { getGlobalState } from '@dr.pogodin/react-global-state';

Gets a GlobalState instance from the context.

caution

In most cases you should use useGlobalState() and other hooks to interact with the global state, instead of accesing the GlobalState object directly.

The TypeScript signature of this function is

function getGlobalState<StateT>(): GlobalState<StateT>;

Generic Parameters

  • StateT — The global state type.
tip

Alternatively you may use withGlobalStateType() function to get getGlobalState() with "locked-in" StateT:

import { withGlobalStateType } from '@dr.pogodin/react-global-state';

const { getGlobalState } = withGlobalStateType<StateT>();

Result

Returns GlobalState<StateT> instance.