1

I am creating an app that contains 2 sub-app components. each one has it's own store/reducers etc. The sub-app components are rendered in a parent component that holds a "Main" redux-store with shared redux-props (eg. user name, is loading state etc.) I can't seem to use the redux-connect in the sub-app in order to access the "Main" store, so what I currently am using is react-context. I pass the "Main" store as context to each of the sub-app components. and when I wish to access the redux-state, I use

this.context.store.getState(...) or this.context.store.dispatch(...)

Is there a better, more esthetic way to do this? Is there a way to use the "redux-connect" accessing the "Main" redux-store?

Shai Kimchi
  • 746
  • 1
  • 4
  • 22
  • 1
    Your app should only have one redux store. Why don't you just split one main store into parts by using multiple reducers? – Domino987 Aug 04 '19 at 07:16
  • Interesting... I used these guidelines - https://redux.js.org/recipes/isolating-redux-sub-apps. But still, how do I get one component to use a certain reducer and the other component to use the other reducer? since the sub-apps are wrapped in a provider store? – Shai Kimchi Aug 04 '19 at 07:41
  • It says: For “product hubs”, “dashboards”, or enterprise software that groups disparate tools into a unified package, give the sub-app approach a try. Does that describe your app accurately? If not and your team is smaller than 100 people, you should probably stick with one store. For your second question. All reducers will be checked, but only the once where the action type match will do something. That is why your action type should be unique. – Domino987 Aug 04 '19 at 07:58
  • yes, it does answer the above recommendation. I am considering using "redux-subspace". do you have an example for the separate reducers approach? – Shai Kimchi Aug 04 '19 at 08:04
  • You can [this link](https://redux.js.org/api/combinereducers#combinereducersreducers), where it is described. – Domino987 Aug 04 '19 at 08:17
  • I think I understand... for eg. does this mean that a typical 'mapStateToProps' will look like this : return { fooGlobalState:state.foo, barLocalState: state.app1.bar}? – Shai Kimchi Aug 04 '19 at 08:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/197442/discussion-between-domino987-and-shai-kimchi). – Domino987 Aug 04 '19 at 08:26

0 Answers0