reduxjs/react-redux · error

could not find react-redux context value; please ensure the

Error message

could not find react-redux context value; please ensure the component is wrapped in a <Provider>

What it means

useReduxContext reads the react-redux Context; if no value is present it means the hook ran outside any <Provider>. react-redux throws this in development so you get a clear message instead of a confusing 'undefined store' failure later.

Source

Thrown at src/hooks/useReduxContext.ts:17

import { React } from '../utils/react'
import { ReactReduxContext } from '../components/Context'
import type { ReactReduxContextValue } from '../components/Context'

/**
 * Hook factory, which creates a `useReduxContext` hook bound to a given context. This is a low-level
 * hook that you should usually not need to call directly.
 *
 * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
 * @returns {Function} A `useReduxContext` hook bound to the specified context.
 */
export function createReduxContextHook(context = ReactReduxContext) {
  return function useReduxContext(): ReactReduxContextValue {
    const contextValue = React.useContext(context)

    if (process.env.NODE_ENV !== 'production' && !contextValue) {
      throw new Error(
        'could not find react-redux context value; please ensure the component is wrapped in a <Provider>',
      )
    }

    return contextValue!
  }
}

/**
 * A hook to access the value of the `ReactReduxContext`. This is a low-level
 * hook that you should usually not need to call directly.
 *
 * @returns {any} the value of the `ReactReduxContext`
 *
 * @example
 *
 * import React from 'react'
 * import { useReduxContext } from 'react-redux'

View on GitHub (pinned to 16f1a91eb2)

Solutions

  1. Wrap the app (or the component's subtree) with <Provider store={store}>
  2. In tests, render with a Provider: render(<Provider store={store}><Comp/></Provider>) or use a custom render helper that includes it
  3. If passing a custom context, pass the SAME context to both <Provider context={Ctx}> and useSelector(fn, { context: Ctx })
  4. Deduplicate react-redux: run npm ls react-redux / react and fix duplicate installs or version mismatches

Example fix

// before
render(<Counter />) // test fails: no context
// after
render(<Provider store={store}><Counter /></Provider>)
Defensive patterns

Strategy: validation

Validate before calling

function assertReduxProvider(ReactReduxContext) {
  // In tests, ensure a store exists before rendering hooked components:
  const store = createStore(reducer)
  return function WithProvider({ children }) {
    return <Provider store={store} context={ReactReduxContext}>{children}</Provider>
  }
}

Type guard

function hasReduxContext(ctx: unknown): ctx is ReactReduxContextValue {
  return !!ctx && typeof (ctx as any).store === 'object' && typeof (ctx as any).store?.dispatch === 'function';
}

Try / catch

try {
  renderHook(() => useSelector(selectItems), { wrapper: TestProvider })
} catch (e) {
  if (e.message.includes('wrapped in a <Provider>')) {
    throw new Error('Test setup error: render inside <Provider store={store}>')
  }
  throw e
}

Prevention

When it happens

Trigger: Calling useSelector/useStore/useDispatch in a component rendered without an ancestor <Provider store={store}>, or using multiple React copies/renderers where the context instance differs from the one the Provider used.

Common situations: Testing a component with render() without a wrapper Provider, rendering a portal or second React root outside the Provider tree, a duplicated react-redux package giving two different ReactReduxContext instances, or SSR code paths skipping the Provider.

Related errors


AI-assisted analysis of reduxjs/react-redux@16f1a91eb2 (2026-08-31). Data as JSON: /api/errors/6e5e7704ef2d7c94. Report an issue: GitHub.