dispatch => ({
async onRequestFnord(arg) {
dispatch(actions.fnordRequested());
const result = await service.fnord(arg);
dispatch(actions.fnordReceived(result);
}
});
Or something to that effect.All you have to do is change it to:
const onRequestFnord = (arg) => async dispatch => {
dispatch(actions.fnordRequested());
const result = await service.fnord(arg);
dispatch(actions.fnordReceived(result);
}
// later, in the component
const mapDispatch = {onRequestFnord};
At least thunks also give you access to `getState`, and if you need it, the ability to inject an "extra argument" that might contain something like a service reference that can be mocked for testing.[0] https://blog.isquaredsoftware.com/2017/01/idiomatic-redux-th...
I've found this to be absolutely required, due to users being able to trigger multiple ajax calls that could return in the wrong order. You need getState() to know which one is valid and discard the old results.
I fail to see why adding access to the entire application state is an advantage. This is just cargo culting. In fact that you held up that counter example as a preferable practice tells me everything I need to know about your library.