August 2017
Beginner
374 pages
10h 41m
English
Redux action creators are also simply functions. This means that we can create higher-order action creator functions.
Consider having the following asynchronous action creator function:
const fetchPosts = () => (dispatch) => { dispatch({ type: FETCH_POSTS_REQUESTED }) return fetch('http://localhost:8080/api/posts') .then(result => { dispatch({ type: FETCH_POSTS_RESOLVED, result }) return result }) .catch(error => { dispatch({ type: FETCH_POSTS_REJECTED, error }) })}
Now, let's say that we need a similar function, fetchUsers. We could simply copy and paste the code and change the action types and the URL, but that would duplicate the code and make it harder to maintain. If we copy and paste the code, then every ...
Read now
Unlock full access