In this video.
Let's talk about another hook and that is use reducer.
Use reducer in combination with create context.
It can help us to create large applications for context API.
We can pass in functions or event handler, but with risk reducer it can help us to trigger an event
that can cause a change to the global state.
So any component that have that particular state.
I'm going to have the updated data and use reducer works the same way as Redux.
So if you want to understand Redux, you need to be familiar with use reducer.
If you know Redux, then use reducer.
It won't be easy for you to understand.
So let's say that this is the source of our application data and it is not part of our component.
It is on a different file.
So let's say that this is our component where we want to add to do to our data source here.
And since this component and this data source are not related, how can we trigger an event to add data
into this array of to dos?
That is why use reducer comes into play.
So let's look at the flow.
So as soon as the user click on the add to do, we have what is called dispatch.
So it's going to call a function called dispatch.
And this dispatch, we can get it from the use reducer.
And this dispatch is going to contain what is called payload or the action object.
So the action object is the data that the user is trying to submit, and then the dispatch will take
that data and then send it to different place.
So let's see where this data is going to send to.
Next is a row pass to what is called reducer.
So reducer is a function that is going to make changes to the original data.
So I regard reducer as a state changer because it's making changes to this original data.
But before the reducer can make changes to this data, we have what is called action type.
Meaning what kind of action do you want this reducer to take?
So the dispatch function will come with a type of an action and then we are going to implement that
logic inside the reducer, the reducer, the action type which has a payload of to do or title call
study, want to add data into the array of to dos or we won't remove a data from the original array.
So always the reducer is going to look up the type of action that is coming in.
So if the reducer has the same action type, then it's going to make changes to the original array.
And as soon as it makes changes, it's going to render a component, and then the original data will
be sent to the component.
So it can see that the to do component now has the new to dos before there is no to do it here.
And after adding we can also fetch the updated to do so in the next video.
Let's see it.
Record how we are going to implement this by building to do application.