useDispatch or useSelector throws: could not find react-redux context value
Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider>Short answer
React Redux hooks read the store from React context. The error means no Provider sits above the component that called the hook. Wrap the app in a Provider with your store. In tests, render through a wrapper that adds one. In the Next.js App Router, put the Provider in a file marked use client.
Fix it fast
1Find out which cause you have
Find where the failing component is rendered, then check that a Provider with a store prop is one of its ancestors. In a test, the component is often rendered alone.
grep -rn "<Provider" src app --include=*.js --include=*.jsx --include=*.ts --include=*.tsx2Match what you see, then jump to its fix
- 1
The error appears on first render in the browser or on the device, in any component that calls useSelector, useDispatch or connect.No Provider wraps the component treeFix - 2
The app works, but the same component fails inside a Jest or Vitest test.A unit test renders the component without a ProviderFix - 3
The error appears in a Next.js app/ project, usually after adding Provider to app/layout.tsx directly.Next.js App Router: the Provider is rendered in a Server ComponentFix - 4
A Provider is present above the component, yet the error remains.Provider uses a custom context that the hooks do not useFix
- 1
What does the error look like?
Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider>Could not find "store" in the context of "Connect(MyComponent)"
Cause 1 of 4
No Provider wraps the component tree
1Check
Open the entry file (index.js, main.tsx or App.js) and look at what is rendered at the top. Hooks and connect get the store through React context, and Provider is what puts it there.
grep -rn "createRoot\|registerRootComponent\|AppRegistry" src index.js App.js 2>/dev/null2Fix
Render Provider once, around the whole app, and pass it your store.
import { createRoot } from 'react-dom/client'
import { Provider } from 'react-redux'
import { store } from './store'
import { App } from './App'
createRoot(document.getElementById('root')).render(
<Provider store={store}>
<App />
</Provider>
)3Verify
Reload the app. The component should render without the error.
npm run devConfirmed by redux.js.org
Cause 2 of 4
A unit test renders the component without a Provider
1Check
Look at how the test renders. A plain render(<Component />) from React Testing Library has no store above the component.
grep -rn "render(" src --include=*.test.* | head2Fix
Write one custom render function that creates a fresh store per test and wraps the UI in a Provider, then use it in every test that needs Redux.
// utils/test-utils.tsx
import { render } from '@testing-library/react'
import { Provider } from 'react-redux'
import { setupStore } from '../app/store'
export function renderWithProviders(ui, { preloadedState = {}, store = setupStore(preloadedState), ...options } = {}) {
const Wrapper = ({ children }) => <Provider store={store}>{children}</Provider>
return { store, ...render(ui, { wrapper: Wrapper, ...options }) }
}3Verify
Swap render for renderWithProviders in the failing test and run it.
npx vitest run # or: npx jestConfirmed by redux.js.org
Cause 3 of 4
Next.js App Router: the Provider is rendered in a Server Component
1Check
Layouts and pages are Server Components by default, and React context is not supported there. Check whether the file that creates the Provider has a use client line at the top.
head -n 3 app/providers.tsx app/layout.tsx2Fix
Move the Provider into its own Client Component that accepts children, and render that from the layout. Any component that calls a Redux hook also needs use client.
// app/store-provider.tsx
'use client'
import { Provider } from 'react-redux'
import { store } from '../lib/store'
export default function StoreProvider({ children }: { children: React.ReactNode }) {
return <Provider store={store}>{children}</Provider>
}
// app/layout.tsx
import StoreProvider from './store-provider'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html><body><StoreProvider>{children}</StoreProvider></body></html>
)
}3Verify
Restart the dev server and open a route that reads from the store.
npm run devConfirmed by nextjs.org
Cause 4 of 4
Provider uses a custom context that the hooks do not use
1Check
Search for a context prop on Provider. If one is set, every connected component must use that same context.
grep -rn "context=" src | grep -i provider2Fix
Remove the custom context unless you really need two stores. If you do, pass the same context to every connect call that belongs to that store.
<Provider store={store}>
<App />
</Provider>3Verify
Run the app again and open the screen that failed.
npm run devConfirmed by redux.js.org
How do I stop it coming back?
- Keep one renderWithProviders helper and ban plain render in tests for connected components.
- Mount Provider once, at the top of the entry file or one root layout component.
- In Next.js, give every file that calls a Redux hook a use client line.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb apps
next/link throws React.Children.only on its children
Error: React.Children.only expected to receive a single React element child.
React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fix