Troubleshooting
Causes and fixes for missing updates, extra renders, context errors, persistence mismatches and debug counts.
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
dependenciesso 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. UsecreateSelectorHookwith 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
use hook must be used within a ContextProviderA 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
createGlobalState<State>(initial, options) does not compileAnnotate the initial value instead of passing a type argument. See TypeScript.
reset() does not restore the initial state in a test
reset() does not restore the initial state in a testThe 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.