pepperoni-app-kit
pepperoni-app-kit copied to clipboard
Correct way to trigger action when routing/ Correct Usage of redux loop
I was wondering what the correct way to trigger an async data-fetching action at the same time as a route push is.
I considered these two possibilities:
- dispatch multiple actions at the view level in my onPress method.
- dispatch a custom Navigation Action from the view, and this returns a redux-loop which fires off both the routing action and the async data-fetching action
At the moment, I'm using redux-loop extensively. Only ever triggering a single action from the view, and letting my reducers with redux-loop handle when I need to do multiple things at once. Is this ok?
You might need to provide a concrete example. Gist? If I understood correctly what you are trying to achieve I would:
- define the fetch method in a service file, which will know about endpoint configuration etc...
- import it into a
*State.js
file and wrap it so it can be exported to a viewContainer - define my function in the ViewContainer and pass them with
mapDispatchToProps
, common use of redux connect - use the function in the view. For example you can bind it to onPress
- dispatch multiple actions from the success and failure of the promise in the
*State.js
file - the dispatch could feed into some reducer that trigger a re-render of the mounted view
Alternatively you could just load some data directly in the View with componentDidMount()
or componentWillMount()
.
Hopefully this would help