is the action to POST_FAVORITE.
Now, I separate the POST_FAVORITE
from the other action called Add_Favorite.
The reason is that the Post_Favorite should be an action which would actually
push the favorite to the server and would update the favorites on the server side,
and then when the server gets updated the server needs to reply back to you saying
the favorite is properly updated.
And then that happens you will update your local store.
Now, in this course we don't have the support on the server side for
maintaining our favorites, so I am not going to do that part,
but I will set up the structure in place now then we do the No disk course.
Then we will set up our server to be able to track favorites from each user.
because there, we will look at authenticating users and so on.
So at that point, we will be able to post the favorites for a user directly to
the server, and when the server gets updated, then you will update your local
Redux store to reflect the change in the favorites on the server side.
And, in this case, in this exercise I'm only going to
update the Redux store directly, but I will go through the two step process.
First, I will Post_Favorites, and that will trigger the Redux tank.
And then which in turn will post a favorites into
my Redux tool using the ADD_FAVORITE action.
Once we have set up these two action types, let's go into the Redux folder and
add a new reducer here called favorites.js.
Now, in that favorites.js file,
let me import * as ActionTypes
from action types.
And set up the reducer here so the reducer here, so
the reducer is export const favorites the reducer is called favorites and
this one takes the state which would be initially an empty array here.
And then the action, add the second parameter and
when this receives the action,
we’ll switch based on the action types and
this is the standard way that you will handle actions here.
So the one action type that we’re going to handle is
the ADD_FAVORITE action type here.
So when you receive the ADD_FAVORITE action
then you will say if (state.some).