export const getPosts = () => dispatch => {
dispatch(setPostLoading());
axios
.get('/api/posts')
.then(res =>{
dispatch({
type: GET_POSTS,
payload: res.data
})}
)
.catch(err =>
dispatch({
type: GET_POSTS,
payload: null
})
);
};
export const addLike = id => dispatch => {
axios
.post(`/api/posts/like/${id}`)
.then(res =>{
dispatch(getPosts())
})
.catch(err =>
dispatch({
type: GET_ERRORS,
payload: err.response.data
})
);
};
In my project whenever a user click on the like button of a post, addLike function will be called with an id of that post.