question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help with React-Redux connect - Could not find "store"

See original GitHub issue

Hi,

I am having issues when trying to use react-redux connect to connect React component to redux store.

I have looked at the redux helpers examples here https://ryandrewjohnson.github.io/react-localize-redux-docs/#redux-helpers and it looks like it should work with react-localize-redux (unless the redux helpers example is not using react-redux).

I used the code sandbox demo (https://codesandbox.io/s/14xp1xy9ql) and added react-redux to the dependencies list and added the following code to Main.js

const mapStateToProps = state => {
  currentLanguage: getActiveLanguage(state.localize).code;
};

export default connect(mapStateToProps)(Main);

But I received the following error.

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

Anyone knows what I am missing?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
invivtas92commented, Jul 1, 2018

Yes, I initially thought LocalizeProvider is meant to replace react-redux’s Provider. Wrapping the application with Provider and LocalizeProvider as follows seems to solve the issue (assuming this is the proper way of doing it)

<LocalizeProvider>
  <Provider store={this.state.store}>
    <Router> 
      <Route path="/" component={props => 
        <Main 
          onToggleClick={this.onToggleReduxClick} 
          toggleValue={this.state.isUsingRedux} 
        />
      } />
    </Router>
  </Provider>
</LocalizeProvider>
3reactions
DGulshancommented, Aug 25, 2018

Docs need to be more clear about this issue. Also, if you wish to use withLocalize HOC to get the translate function prop in your components, you must provide store prop to LocalizeProvider. So the example code block would look something like this:

import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { LocalizeProvider } from 'react-localize-redux'

...

ReactDOM.render(
  (
    <Provider store={this.state.store}>
      <LocalizeProvider store={this.state.store}>
        <Router>
          ...
        </Router>
      </LocalizeProvider>
    </Provider>
  ),
  document.getElementById('root')
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Invariant Violation: Could not find "store" in either the context ...
It's pretty simple. You're trying to test the wrapper component generated by calling connect()(MyPlainComponent) .
Read more >
Could not find - "store" - in - either the context or props
It's saying your connected component cannot be rendered without a store. So, if your current call to shallow is like this: const wrapper...
Read more >
Accessing the Store | React Redux
Could not find "store" in the context of "Connect(MyComponent)". Either wrap the root component in a <Provider> , or pass a custom React...
Read more >
Could not find “store” in the context of connect ? : r/react - Reddit
I tried to solve it using mockStore and wrapping the component around Shallow and Provider.I applied this strategy in my Bill.test.js and App....
Read more >
Provider | React Redux
Could not find "store" in the context of "Connect(MyComponent)". Either wrap the root component in a <Provider> , or pass a custom React...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found