Skip to main content

getSsrContext()

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

Gets SsrContext object (the server-side rendering context, which is used to pass global-state-related data between rendering iterations).

The TypeScript signature of this hook is:

function getSsrContext<StateT>(
throwWithoutSsrContext = true,
): SsrContext<StateT> | undefined;
tip

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

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

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

Generic Parameters

  • StateT — The type of global state content.

Arguments

  • throwWithoutSsrContextboolean — If true (default) this hook will throw if no SSR context is attached to the global state. Pass in false to not throw in such case. In either case the hook will throw if no parent GlobalStateProvider (hence no global state) is found.

Result

Returns SsrContext<StateT&gt object, or undefined (if throwWithoutSsrContext set false, and there is no SsrContext).

caution

This hook throws in these cases:

  • If current component has no parent GlobalStateProvider in the rendered React tree.
  • If throwWithoutSsrContext is true, and there is no SSR context attached to the global state provided by GlobalStateProvider.