Questions about using Redux in React Native?
滿天的星座
滿天的星座 2017-05-19 10:20:14
0
2
577

Currently there is a scenario: Deeply nested sub-components (display components) need to trigger actions (such as routing jumps), and you want to avoid passing related action creator or dispatcher methods layer by layer. So I want to do this:

Set the redux store instance as a global object, that is, global.store = store, and then store.dispatch() can be used anywhere and at any time.

It means that the mapDispatcherToProps method of react-redux is no longer used.

Are there any problems or pitfalls in doing this?

滿天的星座
滿天的星座

reply all(2)
Peter_Zhu

This obviously goes against the original intention of redux design. Any component can modify its state through the global store. It is recommended to place the action trigger in the root component. As for the deep components, the root component can be notified through events, and then the component triggers the action. Secondly, it is generally not recommended to have a component nesting level of more than 3 levels. You can consider whether it is really It is necessary to use the form of parent-child components and whether parts can be replaced by sibling components.

大家讲道理

This approach works logically, but the main pitfall lies in server-side rendering.

If you do server-side rendering, the server needs its own store for rendering

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template