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.

Invariant Violation with Redux connected components

See original GitHub issue

I’m hitting an Invariant Violation error that goes like this:

Invariant Violation: Could not find "store" in the context of "Connect(ConnectedSubComponent)". 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(ConnectedSubComponent) in connect options.

I’ve noticed that this only happens when using react-redux connect() to connect a component into redux store and placing this as the child component in the popup dialog.

I reproduced the error for you to take a look at here: https://github.com/tuomohopia/reduce-fail

Am I using this library the correct way or is this an actual bug that is discovered?

I’m using Android with emulator.

Versions:

  • Windows 10
  • node v10.15.3
  • react-native-popup-dialog 0.17.0
  • react-native v0.59.2
  • redux 4.01
  • react-redux 6.01

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
MasoudShahcommented, Jan 31, 2020

The workaround is to wrap the content inside the modal, with a provider that consumes the relevant reducers. I overcame the problem with this method. The example is as below:

// the reducers contain the one that the component inside the modal targets
const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));

<Modal
  visible={this.state.modalState}
  onDismiss={() => {
	...
  }}
  onTouchOutside={() => {
	this.setState({modalState: false});
  }}
  onHardwareBackPress={() => {
	this.setState({modalState: false});
	return true;
  }}>
  <Provider store={store}>
	<View>
	// the content
	</View>
  </Provider>
</Modal>
0reactions
jacklam718commented, Dec 16, 2020

This problem has been resolved in version v0.20.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invariant Violation when using react-redux connect with react ...
Anyone coming across this issue, I believe this happens because of the react-native and react-redux versions. See this for a tiny bit more ......
Read more >
Invariant Violation with Redux connected components #168
This is most likely caused by React Native Modals not supporting the new React Context API. Can anyone verify this is the reason?...
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 >
Redux testing - Invariant violation error - Hao's learning log
I came across this error "Invariant Violation: You must pass a component to the function returned by connect.
Read more >
[Solved]-Jest testing redux connected component gives error ...
Coding example for the question Jest testing redux connected component gives error " please ensure the component is wrapped in a "-Reactjs.
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