react-native-modals icon indicating copy to clipboard operation
react-native-modals copied to clipboard

Invariant Violation with Redux connected components

Open tuomohopia opened this issue 7 years ago • 18 comments

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

tuomohopia avatar Mar 27 '19 18:03 tuomohopia

The relevant code is in the App.js file: https://github.com/tuomohopia/reduce-fail/blob/master/App.js

Otherwise it's just a react-native init bootstrapped setup.

tuomohopia avatar Mar 27 '19 18:03 tuomohopia

For the record, I'm still experiencing this issue in the just released version 0.18.2

tuomohopia avatar Apr 01 '19 13:04 tuomohopia

I believe I have a similar issue. I have a component using context api in HOC, I place this component inside and the consumer of the component's value becomes null.

EndlezzCoding avatar Apr 12 '19 09:04 EndlezzCoding

@atominvention did you try if the problem persists with the just released react-redux version of 7.0.1?

tuomohopia avatar Apr 12 '19 09:04 tuomohopia

I'm still experiencing this at react-redux v.7.0.2.

tuomohopia avatar Apr 13 '19 13:04 tuomohopia

Just having this issue too after upgrading react-native-popup-dialog from 0.10.46 to 0.18.2.

Versions: react-native-popup-dialog 0.18.2 react-native v0.59.2 redux 4.01 react-redux 7.0.2

tikkichan4 avatar Apr 16 '19 11:04 tikkichan4

I am having the same issue, any workaround?

kamiyaki22 avatar Apr 24 '19 12:04 kamiyaki22

This problem still seems to persist, pls fix

JensKolb avatar Jul 21 '19 19:07 JensKolb

Also facing this issue :(

Trashpants avatar Aug 05 '19 14:08 Trashpants

I'm currently facing this issue too. No one has solved it?

gonzer31 avatar Sep 19 '19 19:09 gonzer31

I'm having the same issue

martinsd94 avatar Oct 01 '19 18:10 martinsd94

We resorted to using React Native Elements Overlay, which basically handles the same but without any problems. Before we used to pass the relevant redux store items manually as props to the component.

JensKolb avatar Nov 03 '19 17:11 JensKolb

Same problem with:

react-native-popup-dialog 0.18.3 react-native v0.61.4 redux 4.0.4 react-redux 7.1.3

alisn72 avatar Nov 20 '19 07:11 alisn72

This is most likely caused by React Native Modals not supporting the new React Context API. Can anyone verify this is the reason?

CoenWarmer avatar Dec 05 '19 10:12 CoenWarmer

I am also affected by this issue. Tried to inject the store inside the dialogue using ReactReduxContext but that also didn't work. So I think you might be right @CoenWarmer

ferdynator avatar Jan 03 '20 11:01 ferdynator

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>

MasoudShah avatar Jan 31 '20 08:01 MasoudShah

We still need a solution for this.

lucasfeijo avatar Apr 01 '20 16:04 lucasfeijo

This problem has been resolved in version v0.20.1

jacklam718 avatar Dec 16 '20 20:12 jacklam718