Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find "store" in either the context or props

Tags:

reactjs

redux

I have this error :

Uncaught Invariant Violation: Could not find "store" in either the context or props of "Connect(ItemIndex)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(ItemIndex)".

My code is :

const createStoreWithMiddleware = applyMiddleware(
  promise
)(createStore);

ReactDOM.render(<ItemIndex />, document.querySelector('.container'));

How to resolve this error?

like image 291
Reda Avatar asked Feb 15 '16 23:02

Reda


People also ask

Why my Redux is not working?

It doesn't work because your action creator is just a function that returns an action. It is up to you to actually dispatch it. We can't bind your action creators to a particular Store instance during the definition because apps that render on the server need a separate Redux store for every request.

Can't find the react Redux context value react native?

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> If you need to access redux store in App component, you should wrap the App component with <Provider /> , so that it can provide the react-redux context values to App and other nested components.

How do you test connected components in react redux?

import {render, screen} from "@testing-library/react"; import {Provider} from "react-redux"; import {createStore} from "../../app/store"; import {Counter} from "./Counter"; describe('Counter component', () => { test('renders the counter component', () => { render( <Provider store={createStore()}> <Counter /> </Provider ...


1 Answers

I forgot to add the provider

import { Provider } from 'react-redux';

ReactDOM.render(
  <Provider store={createStoreWithMiddleware(reducers)}>
    <ItemIndex />
  </Provider>
  , document.querySelector('.container'));
like image 176
Reda Avatar answered Sep 20 '22 02:09

Reda