August 2017
Beginner
298 pages
7h 4m
English
Since adding a post is an action related to posts, we will add the actions in the same postActions.js file. Add the following code for addNewPost action, which also acts as the dispatcher for adding a new post in your postActions.js file:
export const addNewPost = (body) => { return dispatch => { dispatch(addPostApiCallStart()); apiCall(`post`, body) .then(() => { dispatch(addPostApiCallSuccess()); dispatch(getAllPosts()); // Dispatch - getAllPosts action }) .catch(error => { dispatch(addPostApiCallFailure()); }); };};
The addNewPost action is pretty much similar to our preceding getAllPosts action. However, it requires a body argument, which will contain the post details needed for adding the post to the server. You should ...
Read now
Unlock full access