{"record":{"id":"6e5e7704ef2d7c94","repo":"reduxjs/react-redux","slug":"could-not-find-react-redux-context-value-please-e","errorCode":null,"errorMessage":"could not find react-redux context value; please ensure the component is wrapped in a <Provider>","messagePattern":"could not find react-redux context value; please ensure the component is wrapped in a <Provider>","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hooks/useReduxContext.ts","lineNumber":17,"sourceCode":"import { React } from '../utils/react'\nimport { ReactReduxContext } from '../components/Context'\nimport type { ReactReduxContextValue } from '../components/Context'\n\n/**\n * Hook factory, which creates a `useReduxContext` hook bound to a given context. This is a low-level\n * hook that you should usually not need to call directly.\n *\n * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.\n * @returns {Function} A `useReduxContext` hook bound to the specified context.\n */\nexport function createReduxContextHook(context = ReactReduxContext) {\n  return function useReduxContext(): ReactReduxContextValue {\n    const contextValue = React.useContext(context)\n\n    if (process.env.NODE_ENV !== 'production' && !contextValue) {\n      throw new Error(\n        'could not find react-redux context value; please ensure the component is wrapped in a <Provider>',\n      )\n    }\n\n    return contextValue!\n  }\n}\n\n/**\n * A hook to access the value of the `ReactReduxContext`. This is a low-level\n * hook that you should usually not need to call directly.\n *\n * @returns {any} the value of the `ReactReduxContext`\n *\n * @example\n *\n * import React from 'react'\n * import { useReduxContext } from 'react-redux'","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/reduxjs/react-redux/blob/16f1a91eb2cc3817bf63753e8c90e528a9f0580c/src/hooks/useReduxContext.ts#L1-L35","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Wrap the app (or the component's subtree) with <Provider store={store}>","In tests, render with a Provider: render(<Provider store={store}><Comp/></Provider>) or use a custom render helper that includes it","If passing a custom context, pass the SAME context to both <Provider context={Ctx}> and useSelector(fn, { context: Ctx })","Deduplicate react-redux: run npm ls react-redux / react and fix duplicate installs or version mismatches"],"exampleFix":"// before\nrender(<Counter />) // test fails: no context\n// after\nrender(<Provider store={store}><Counter /></Provider>)","handlingStrategy":"validation","validationCode":"function assertReduxProvider(ReactReduxContext) {\n  // In tests, ensure a store exists before rendering hooked components:\n  const store = createStore(reducer)\n  return function WithProvider({ children }) {\n    return <Provider store={store} context={ReactReduxContext}>{children}</Provider>\n  }\n}","typeGuard":"function hasReduxContext(ctx: unknown): ctx is ReactReduxContextValue {\n  return !!ctx && typeof (ctx as any).store === 'object' && typeof (ctx as any).store?.dispatch === 'function';\n}","tryCatchPattern":"try {\n  renderHook(() => useSelector(selectItems), { wrapper: TestProvider })\n} catch (e) {\n  if (e.message.includes('wrapped in a <Provider>')) {\n    throw new Error('Test setup error: render inside <Provider store={store}>')\n  }\n  throw e\n}","preventionTips":["Create a test render helper that always wraps in Provider","Use one react-redux + one react package version (npm ls react react-redux)","In multi-root/portal apps, re-provide the store near each root or pass the context explicitly"],"tags":["react-redux","hooks","provider","context"],"backgroundTag":"missing-redux-provider","analyzedSha":"16f1a91eb2cc3817bf63753e8c90e528a9f0580c","analyzedAt":"2026-08-31T22:28:37.628Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}