Skip to content
react-global-state-hooks

Troubleshooting

Causes and fixes for missing updates, extra renders, context errors, persistence mismatches and debug counts.

Problem solvingTypeScriptTry an example

The component does not update

  • You changed the state in place. Subscribers are notified only for a new reference. Return a new object or array from the updater.
  • You changed metadata. Metadata never triggers a render. Put displayed values in the state.
  • The selector reads something outside the store. List it in dependencies so the selector runs again.

The component renders too often

  • The selector builds a new array or object. Strict equality sees a change every time. Pass isEqual: shallowCompare. Use createSelectorHook with that equality option to share a derivation across components.
  • There is no selector. useStore() subscribes to the whole state.

use hook must be used within a ContextProvider

A context hook ran outside its Provider. Wrap the component, or in tests pass the wrapper from Ctx.Provider.makeProviderWrapper().

An action throws “Every key inside the storeActionsConfig must be a higher order function”

An action returned something other than a function. Each action must look like name(args) { return (tools) => { ... } }.

Hydration mismatch with persisted state

The store restores from localStorage when its module loads, which is before hydration. Render the default value first and switch to the stored one after hydration. See Persistence.

createGlobalState<State>(initial, options) does not compile

Annotate the initial value instead of passing a type argument. See TypeScript.

reset() does not restore the initial state in a test

The store was created from a plain value, so reset() keeps the current one. Use a function initializer, or call reset(state, metadata).

Render counts double in development

React Strict Mode performs extra renders and replays effects in development. The demos count commits in an effect and skip the simulated remount so the counters reflect committed updates.

Documentation
↑↓ Navigate ↵ Open Esc CloseRGSH docs
Get started

Shared state. Precise subscriptions.
Built-in DevTools.