Hi and welcome back to our series on react native and redux toolkit.
Today we're going to be talking about one of the most important concepts in.
Redux toolkit called combining reducers.
In redux a reducers is a function that updates the state of your application
in response to an action and we just created one in the last video.
But as your application grows in complexity,
you may find yourself with many different
reducers, each managing its own part of the state.
Like we could have a user reducer, we could have a single donation reducer.
We could have all of the donations
reducers and it might get complicated to.
Manage all of these so you might want
to combine all of these into a single root reducer.
And combining reducers is useful because it
improves your code organization and with multiple
reducers, managing different paths of the state
will be easier and your code will.
Be easier to understand and maintain.
Also you will write more modular code.
And by breaking down the state management
into smaller pieces you can write more
modular and reusable code and it offers.
You a better scalability because as your
application grows you
can add new reducers
to manage new paths of the state making
it easier to scale your application.
So let's use the combine reducer function
right now let's create a new file inside our redux folder called store JS.
And here we're going to import combine
reducers from redux JS toolkit actually.
So redux JS toolkit great.
And then we are going to import our
individual reducers and we only have one so far.
So let's import user from reducers user JS file
and then let's create a root reducer constant and we're going to.
Be using combine reducers and we're going.
To say that we're defining just one
reducer called user and it's going to use the user's reducer.
And actually what we could do is go to our user file and just
export user reducer by default.
And we're not going to have to
type this for each of our modular imports in here.
So that's it for creating root reducer.
And then what we're going to do.
Is we're going to use this root reducer to tie our reducers to our screen.
So for that we're going to need to configure our store and we're going
to go over how to configure figure our store in the next video.
Thanks so much for watching and see you in the next video.