connected-react-router icon indicating copy to clipboard operation
connected-react-router copied to clipboard

Could not find "store" in the context of "Connect(Routes)"

Open clayrisser opened this issue 5 years ago • 2 comments

I get the following error. I have the react-redux <Provider> at the top with store.

Could not find "store" in the context of "Connect(Routes)"

clayrisser avatar Nov 19 '19 13:11 clayrisser

I created an example project and reproduced the issue exactly.

I set it up exactly how the instructions say.

You can find the example at the link below.

https://github.com/codejamninja/react-example

2019-11-19-220259_grim

Could not find "store" in the context of "Connect(App)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(App) in connect options.

clayrisser avatar Nov 20 '19 04:11 clayrisser

Hi, You probably didn't add Provide from 'react-redux' and didn't pass the store to it in index.js file So you should do this in index.js file

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import store from './redux/store';

import './index.css';
import App from './App';

ReactDOM.render(
  <Provider store={store}>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </Provider>,
  document.getElementById('root')
);

Hadeel-Salah avatar Aug 14 '20 15:08 Hadeel-Salah