- Podcasts
- ReactJS Developers Podcast
- Complete React Redux Tutorial | Master State Management with Redux
Complete React Redux Tutorial | Master State Management with Redux
ReactJS Developers Podcast
- December 3, 2026
- 1 h 18 min
- Episode 21
About this episodeManaging application state becomes increasingly important as React applications grow in size and complexity. Redux provides a predictable…
- What Redux is and why it is used in React applications.
- Understanding global state management.
- The role of the Redux Store.
- Understanding Actions and Reducers.
- How the Redux data flow works.
- Connecting React components to Redux.
- Reading application state using selectors.
- Dispatching actions to update the store.
- Managing shared data across components.
- Introduction to Redux Toolkit and modern Redux development.
- Best practices for organising Redux code.
- React JS beginners ready to learn state management.
- Frontend developers building complex React applications.
- JavaScript developers transitioning into professional React development.
- Developers interested in Redux and Redux Toolkit.
- Anyone looking to improve their React application architecture.
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Complete React Redux Tutorial | Master State Management with Redux
Now we are going to discuss Redux and you must be thinking that why are we discussing Redux so much? We should have learned Redux Toolkit directly because Redux Toolkit is running in the market. And people suggest that instead of Redux, we should learn Redux Toolkit. But my suggestion is that the four major state management libraries like Context, API, Just, Redux and Redux Toolkit, you should know these four. Because you will see it being used in the project. I have seen it myself. I have done it. You can get JustStand as well as Redux. If you are making a new project in Redux Toolkit, then it is recommended that you use Redux Toolkit. But if you are getting an old project, then there is a maximum chance, 80-90%, that you will get to see Redux implementation. Or you can get JustStand as well. And if you are creating a new project, then you will get Redux Toolkit. So definitely you should know React, Redux. And if you learn Redux, then there is nothing in Redux Toolkit. Redux is based on Redux. All the understanding of Redux will be useful in Redux Toolkit. Redux has a simpler code in Redux Toolkit. Setup is very easy. So, if you understood Redux, then you got Redux Toolkit. For Redux Toolkit, you don't have to do much. Understand Redux, Redux Toolkit is clear. So, let's quickly start understanding Redux. And before understanding Redux, you should have a proper idea of state management, which we have been discussing from the previous 3-4 lectures. Exactly, this state management is going on in sequence. Then we did context API, just end, and made a project. And now we are doing Redux. But there is no tension. If you don't have an idea of state management, then I will give it to you. Because Redux looks very complicated in itself. So, if anything is missed out of your understanding, then you will not feel much in Redux. Let's discuss state management in short. Those who know it can skip this portion. State management means that if you have multiple components like A and in A you have B component and then C component and in B you have D component and E component and in C you have F component and G component. So, the biggest problem here is of data sharing. If you have to use same state in F and You have to use the same state in F and E. You have to use the same state in F and D. For example, there is a state called count. You have to use it in F. You have to show the count in F. And you have to use the set count in D. You have the idea of the state. I won't go into details about the state. You have seen so many things. That's why you reached here. So, count and setCount. So, in F, we have to show the value of count and in D, we have to do setCount. So, we will need the same state in both. Now, the problem is, how will we share the same state in both? So, there is a lot of difficulty here. If we will make the state in this, in the F component, then first of all, we have to send it in C. And prop drilling, definitely you know that parent is child. We cannot send parent from child. Although, there is also a way of that. I have told you that we can do this through function. So, let's assume that we have sent it from F to C, from C to A, from A to B, then by prop drill, and from B to D. We have sent it in this way. But if you look carefully, D and F needed data, but C, B, A are containing this useless data. Isn't it? It is basically washing the data. And if we have made a state in A, then we can prop drill from A to C, from F to A, and from A to B, and from B to D. But still, again, you have the components here that are washing the useless data. Neat was for D and F, but all the other components are also cleaning up the data, which is not right. It should not be like this. So, its solution is this. The solution is that you make a store here, a global store or a global state. You can say that. Here, make a global state, which can be used by every component. Global state. Okay. It can be used by every component. Or you can also call it a store. In redux, we call it storey. So, here you have made a global state. In this, you have count, set count, both things. So, in redux, actually, it doesn't happen like this. Count, set count, state. It happens in a different way. But, to explain, I am saying, that if you have any states, let's say, you have made any states, so, you can use them in f, c, a, b, because there is no need for probability, there is no dependency. The one who wants can use the state from there. And if any component changes in the store in the state, then everyone else will also know. Re-render will be triggered. Okay? So, you have to keep this in mind. And now let's see what is Redux? And what are Redux and React Redux? Are there any differences between them? So, exactly there is a difference here. And these are the small differences. And there are some theories which you don't understand. So, in the future, it creates a lot of irritation while coding. Because I said that code is very lengthy. It is not complicated at all. It is just lengthy. So, if you are clear about all these things, you will be able to code very easily. You will see that it is not that complicated, it is very easy. It is just a little long. You have to remember the flow. So, here Redux and React Redux are definitely different things. Now, I told you that you have to make a global state or store. So, how will you make a global state or store? So, I told you that you can use the context API to make a context. Or you can use Just End here. And you can also use Redux here. And you will read the Redux toolkit later, you can also use it. So this Redux, you are making a store from it, basically it is a state management library. Now what I have told, you have to manage the state properly, there should be no problem in sharing. So Redux is your state management library. And this is a JavaScript library, many people think that Redux is based on React, Redux is the library of React, it is not like that. Redux is a JavaScript library, which can be used with Angular, can be used with Vue.js, and You have Node.js. So, Redux can be used with multiple things. So, with whom do you have to do it? With React. So, to connect Redux with React, listen carefully. Redux is a library for state management, JavaScript library. You can use it with multiple things. But, with whom do you have to use it? With React. So, to connect Redux with React, you have to install React Redux. We use React Redux. So, you also need Redux. You have to install the Redux library as well as React Redux. Okay, you have to do both. Redux for state management and React Redux for connecting Redux to React. Okay, so you have to do both. So, by using Redux, we will be making store, reducer, action, reducer, store, constant. We will see what all these things are. Don't worry at all. Store, you will understand. Reducer, action, we will understand everything. We will be connecting with React Redux, and for this, we have to provide the provider. You saw that in our context API, we had to provide the provider. We didn't have to do it in gestion, but we had to do it in context. So provider provides you with React Redux to connect with your application, to connect with React. Provider's job is to let you easily flow that state in all components. So here the work of the provider is done. UseSelector and useDispatch, we will see further what useSelector does. Basically, we can take the state from useSelector. And we can dispatch the action using useDispatch. So you will not understand all this in an hour. You will just understand that Redux is a library. And to connect Redux to React, we have to use React-Redux. So we will use both together. So this is what you have to understand. And if you have understood this, then you can easily understand the flow of your redux. And it is not that easy, but I have made it easy for you. I will explain this flow very easily and you will be able to code easily. So here you have state, action, reducer, store, provider. You just have to understand these few things and your work will be done. First of all, you understand that here there is no funda like state and set state. You can change the state from setState to setState. Here you just have the state, nothing like setState. So if you are thinking of this, like you were doing in the context API, the context API is there, so remove it from your mind. And if you are just standing, then it is very interesting for you. You will be able to relate. So nothing like setState, remove it from your mind. You will not get anything like setState here, so that you can update the state. So you will only have state. State means data and all the data will be used in all the components. So if we change the state, will the rerender trigger everywhere and the UI will be updated? It will definitely happen. The problem is how to change the state. How will you change the state? Yes, this is the difficulty. So, to change the state, look, understand from the arrow. The state's access is only available to the reducer. So, who can change the state? Only the reducer can. Okay. And the access of action is available to the reducer. So, reducer basically contains two things, state and action. In which you don't know what action is. You only know what state is. And I just told you that reducer can only change the state. Because the access of state is available to the reducer. Okay. So, the state's axis is with the reducer. The reducer can change the state. Great. Did you understand this much? One line. Okay. One line. Did you understand this much? Now, I am telling you that you don't have any such facility that you can enter the direct reducer and tell what to change in the state. Listen carefully to what I am saying. You don't have any such facility. Like you made a button here. You put onclick on the button. Now what will you do on onclick? You don't have any such facility. Through which you can directly enter the reducer. And tell what to change in the state. Like it used to happen in JustAnd. You had made a function. You used to trigger that function and change it in the state. Isn't it? You triggered the addToCart function. It added it to the cart. You triggered the addToProduct function. It added the product to the state. And if you add the product to the state, then it will render everywhere. But here, nothing like this happens. Here, everything is happening in the reducer. I will explain you how it is done in reducer, then you will understand. Here it is being checked on the basis of condition. First of all, consider that reducer is a function. Reducer is a single function. Now in this function, you are getting two things, state and action. You can understand by looking, right? You can understand by looking that both state and action are present in reducer. Reducer is a simple function. In the parameter of that function, you are getting two things, state and action. In which you don't know the action yet. You know the state. Okay. Now, if you don't know the action, then how will you work here? You will have to tell a little action too. Look carefully at the action here. So here, action is also a function of yours. We will discuss the action again. I want to explain the action a little because it is important for you to understand here. So, there is only one function which is returning plain JavaScript object. We will understand why it is doing and what it is doing. So, plain JavaScript object is returning here, in which type and payload are mentioned. Payload is mentioned later. Type is written here. Action is a function and there can be many actions in every function. Add to product, add to cart. So, all the actions have different types. First action is add to product, so you have given type here. The second action is add to card, so you must have given type here, add to card. Now, this reducer function, the action that is coming to the reducer function, so from action, it is definitely returning an object. So, action dot type, we can access type, okay. Object is returning, so you have an object near action, object has type and payload both, okay. So, action dot type is equal to, we will check that what is add to product, understand my point carefully, if you understand a little bit, then you will understand the code completely, here this function is there, reducer, and here you are getting two things, state and action, and in action you are getting an object, in which type and payload is there, so I have put a condition here, action dot type, if you have add to product, then add to product will work here, and update the state, update the state, okay, update the state, then after that else if, we will put one more condition, you can also use the switch statement here, action.type, if you have a cart here, add to cart, then here we will update the state again, and add some items to the cart, so something like this is working here, okay, so if you look carefully here, then reducer is a function, inside the function, it has two things, which are understood from the diagram, state and action, okay, understood, state, Action is a plain javascript object with type and payload. You can access the object directly from dot notation. I have set the condition action.type. If you have add to product, then you can update the state of the object. And if it is not like that, if add to cart has been triggered here, then in lsip, add to cart will trigger here, will work, and will be updated in the state here, cart will be updated here. So, all the work is happening from here. And who is telling how to do it? It is telling the action. Oh, it is telling the action, yes. So, now you must be understanding a little bit about the action too, that whatever work we will do, it will go to the reducer through the action. Through action, it will go to the reducer. Meaning, if you are putting any onclick here, then you don't have anything direct that you enter the reducer. You have to go here to action. In action, it is definitely returning a plain JavaScript object. So, whatever action it is, if it is an add to product action, then it will be returning an object according to that. If you have an add to cart action, then it will be returning an object according to that. Now, this action will come here in reducer. Type will match which type of action brother has triggered. Okay. Which type of action has been triggered by clicking the button? Add to cart, add to product. So, whatever action has been triggered, match it with its type. and then update the state of the block by working on it. Is it working like this? Exactly. Action will come from action to reducer. Then it updated the state and the render got triggered everywhere. So, the reducer is managing the state and action and the reducer is managing the store. Reducer has all the powers of state and action. Reducer is managed by your store. How will you make a store? I have told you that you will use the Redux library. You can do proper state management with the Redux library. So all this work will be done by it. And provider. Provider. Definitely. You have to connect with your application. With react. So here you will use react redux. React redux. using Redux, you will be providing multiple components. Just like you were providing in context API, similarly, you have to go to main.jsx, there using provider, in all components, basically, you will wrap app.jsx in provider, in all components, that state will be available, and you will be able to use that state. To connect the provider, we will use react-redux. Here you are making a store using redux. You will have a reducer inside the store. It may be one reducer or multiple reducer. It may be that you have made a different product reducer. So there will be a different action related to that. And then you have made a different cart reducer. So there will be a different state and action related to that. And it may be that you have made a reducer for authentication. then your state and action will be different. So, you can make multiple reducers and your state and action will be related to that. And you have to tell all those things in the store. Basically, you don't have to tell everything in the store. You just have to put the reducer. If you put the reducer, then the reducer is handling the state and action. So, the store is handling the reducer and the reducer is handling the state and action. This is the flow that you have to understand. The state is handling the reducer and the reducer is handling the action and state. Go to the store and install multiple reducers. First we will install single reducer, then we will see how to install multiple reducer. Then there are many extra things that we have to discuss. For example, Redux Persist is also a library through which you can persist data, which was done very easily in Just Stand. Here it is a bit complex. And you understood the provider. If you understood this much, And action, I have told you a little less, so you know about this question, that this is also a function of yours, and the function is returning you a plain JavaScript object, and action itself is telling you in your reducer what to do. So in action, as such, you are not doing anything, you just return this plain JavaScript object and your work is done. Okay? Okay. Very good. And you are providing it to the provider. Now if you want to use the state, then how will you use it? You already know this. Well, the create is done, the create of the store is done, the provide is also done. How will you use it? It is important to use it. So to use the state, you have a useSelector here. UseSelector hook. Now to use it, that means to use it in react, then to connect react, to connect it, where will the useSelector come from? React Redux. So wherever there are connectivity things, you understand that it is going to come from React Redux. Okay. If you want to use action, then to use action, useSelector? No. Here you have useDispatch. Dispatch. To dispatch action, useDispatch. Otherwise, how will you know that you dispatch action on the basis of Redux? Because action is also a function. Normally, if you call a function, then what will happen? Nothing will happen. Action is linked to reducer. So, you have to dispatch action through dispatch. Only then you will know that you have to work in reducer. Otherwise, it will be treated like a normal function. Use Dispatch for dispatching action and Use Selector for selecting the state. If this is clear to you, then you can move ahead. Theories are written here. Redux, action, reducer, provider, use selector, hook, use dispatch. I have taken a diagram here. You can find it on the internet. It was a gift but I have converted it into a photo and given it to you. So here is your UI, you are doing a click event on the UI, which is the deposit one, basically it should be deposited. So it will go here, basically you have dispatched a function, now I have told you that you have to dispatch an action, not a function, it should be called an action. action, using event handler, you have dispatched an action. Now, if you have dispatched an action, then definitely it has an object, type and payload. It will take type and payload here, and here it will tell what to do in reducer, it will work and update in state, and after updating, it will reflect in UI. So, this is some flow. Okay. This is how your flow is working. Let's recap once more, because look, it is simple, But when you go to code, then you have to keep all these things in mind, otherwise confusion will happen. So that's why I am saying, give time, give a little time. This is understood, Redux is understood, there is nothing in Redux toolkit. Your work will be done very easily. So, you are providing and making a store. Now, you will have multiple reducers in the store. You can make product reducer, cart reducer, authentication reducer. You will have access to the state and action of the reducer. This is also a function of yours. In the function, you will get the state and action. Here you can check how to work. And the rest you are knowing, state and action. So, there is so much flow that we have put on click here. On click. Here we have displayed. dispatched an action, dispatched the action, then it will come here, whatever action we dispatched, according to that, type and payload will be returning, according to that, it will come here and check the type, which type is this, according to that, it will work, and after working, it will go to the state, it will update in the state, it will update in the state, then it will be updated in the UI, Alright. Good, good, good, good. Now, you have understood so much. You have understood so much. So, there is nothing more than this. Now, we can move towards code. And we can code and see. Just keep this diagram in your mind. You will enjoy the rest of the code. Okay. Come on, let's quickly come to code. So, as always, I have set up VEET properly, folder structure, etc. And I have installed Tailwind CSS, if you need styling, etc. Rest, you can also do normal CSS. The topic is not that, the topic is Redux. So, we have to discuss Redux here. Basically, we have to discuss code. So, first of all, what we have to do is install. What all we have to install, quickly tell me, so I will be happy. First of all, we will come to the CD VEET folder, CLS. And what all we have to install, quickly tell me. I have told you two things which are important for Redux. First of all, you have to do NPM iRedux state management library and you have to connect Redux to react. React Redux. I told you so much. If you remember so much, then you will work. And at last, I don't know how this stick got stuck. Okay, so let's install it quickly. So it will be installed quickly and we will clear it and run it from NPM run dev. And here we will click on control. So our project is running. It is empty now, so nothing is visible. Let's say hello from H1 here. See, hello is coming. Wow, it's fun. And I close this and this size is fine. I have zoomed in, so you can see it clearly. And quickly make a store. And the first thing we will do here is to make a store and provide it. We will create a store and provide it. After that, we will see whatever work is done inside. Because it will take a little time. So first of all, let's make a store and provide it. So we will be free from one thing that we do not have to provide later. We can use it directly. First of all, make a store. Come here and create a new folder of Redux. Maintain the folder properly for Redux. Because the code I told you is long and lengthy. So it is very important to maintain it properly. So here store.js. And we will make JS only. Because JSX etc. So we don't have to return here. Store.js And here we have to import. Create store. And if we are not getting suggestions. Then there is no issue. Create store will come from Redux. Keep in mind. Whenever you have to connect Redux. Basically you have to use. Connect with your application. Then only we will use React Redux. Otherwise Redux. So create store will come from Redux. Create store. Very good. And now come here. createStore and make it store. store is equal to createStore and this is our store. Wow! And export default store. Here, store is made. Was it so simple? No, it is not that simple. Now, I have just written a starting boilerplate. Basically, store is made and default is exported. And here, we will quickly connect to main.jsx. Now, to connect, to connect, quickly tell me, we have to use react-redux. And first of all, we will need a provider here. So, import, import, If you are not getting the suggestion, then you have to keep in mind that if you are not getting the suggestion, then you have to keep in mind that if it is coming from redux, then it is coming from redux. And if it is named export or default export, then it is named export provider. So you have to take it this way. Rest, you don't have to remember anything. If it is in your mind, then it is fine. Otherwise, go to Google and do it. There should be no shame in it. You will not be able to remember all these things. The syntax is very long here. I have worked on it many times, so I remember a few things. If I forget the rest, I will do it in front of you. So the provider came here and here we will wrap the application with the provider. Now whatever we do in the application, I'm talking about the application, basically app.jsx should be called. The file of the app will have all the components. So now we can use it everywhere in the app. And along with that, we will use the app to make the components. So we can use our state in all those things. So we made the provider and wrapped it in the provider. We basically wrapped the provider, but we didn't mention that we are providing the store or not. So here you have a props named store. You have to put your store in this store. So quickly import your store. Import. Store. See, suggestions are also coming. Wow. So default export was here. So here we have imported the store by default. And we will put this store here. That's it. It's done. Okay. Provider's work is done. Provide's work is done. Rest of the work will start now. So, we made a store. Simple. Provided the store. That's it. Wrapped it with the provider and passed the store inside the store. Our main.jsx is provided. You don't have to look at it upside down. Okay. Provided. Provided. Doing it together will not be fun at all. If you watch it like a movie, then stop the video. No use watching it. Do it together. As I am telling you, make a folder as usual. Arrange the code as usual. Flow is very important. You will get the rest of the code anywhere. So, we will close main.jsx. We have made this store. Okay. First of all, link the reducer to this store. We have made a sequence store. What will be in the store? Reducer. What will the reducer be managing? State and action. Okay. So first of all, we have to make a reducer. Yes, we have to make a reducer. So for the reducer, I will make a reducer folder. And I will keep all the reducers in this reducer. Okay. I am repeating again and again. Arrange the code here very properly. Otherwise, the game is over. So here I make productReducer and name it productReducer.js. And what is reducer? You tell yourself what is reducer? I told you a little while ago, what is reducer? It is a normal function which provides both state and action and works on its basis. So it is a normal function. We are doing default named export here. Export default. Sorry, I am saying export default and not named export. Export const. Let's make it first. Const product reducer. Okay. This is our function. Okay, function is done. Now in function you are getting by default state and action. How? How? Where did state and action come from? This is a normal function. So where did state and action come from in function? From here, we will put the product reducer in the store. Product reducer. It is linked to redux. The product reducer is linked to the store. Now, because the product reducer is linked to the store, then in the product reducer, you will have state and action. Trust me a little. Okay, product reducer. Until the product reducer was not linked, this was a normal function here. So, there is nothing about state action. You will not get state action here. But I connected the product reducer to the store. Now, because I connected it to the store, then this is your This is not a normal function, this is your reducer. If it is a reducer, then you will get state and action here. Now you can give any name here. I will give the name state and action here. You can give my state and my action here. Keep in mind that the first parameter is the state and the second is the action. Then what did I tell you? All the work is happening inside the reducer. The state is basically with the axis reducer. And how it happens, I will tell you right now. Because your state is being made here. I will name it as initialState. And basically it is standard. You can name it as anything. But if you see in code, you will get initialState in the same way. And what I am making in this? I am making products. For now, I am just making products. You can keep more key value pairs here. For now, I want to make products in productCard. There can be something else like loading etc. So, I don't want to do that now. So, I will pass initialState in this state. So, we got state, this is our state, this is our state, we will use this, yes, we will use this. Now, how will we change it, how will we manipulate it? So, for that, here you have, I told you, action.type, action.type, although we have not made action yet, but we know, from action, an object is coming, plain JavaScript object, in which type is there, payload is there, so payload also has nothing to do with it, type we have read, that yes, type will be there in it, we will make action in the same way, that it will be returning an object, in which type will be there, Since this is an object, we can access the type with action.type. You can also use switch case statement. You will find switch case statement in many places. I feel if else is more comfortable, so I am using if else. If we have action.type here, let's assume add to product. So why am I writing capital letter here? Standard naming convention, we usually do it this way. Wherever you look, you will find it written this way. And this is better too, you should write it this way. And it should actually be made constant. Why should it be made constant? I will tell you that right now. But for now, you can do it this way, add to product. You can give anything here, your choice. Give add to product, give add product. So I gave add to product. Now it will add a product to the product. How will it do it? It will add in the state like this. We will not do it now, we will basically return it as it is to the state. It is very important to return. If you do not return, the state will get disturbed. The state will get disturbed. Here it is not a merge funda which you used to see in Just Stand. Although you had to return there also if you do not do anything. So here whatever state you return, it will be set here. So keep this in mind. So I have not done anything for now. I have returned the state. and I will just do CLG here that add to product reducer has been triggered here. Okay. Else if, else if, else if, else if, else if, else if I don't want to do anything right now. So simply by saying else, I will return the state here. And return it very carefully. If you do it or not, do it in else. Because by default, if you don't pass any action here, then which one? block of code will be rendered here. This one. This one will be rendered. I am saying this one will be rendered. This one will be run as block of code. So, if you don't return here, then it will be undefined and error will also be found. And I will show you by doing that. So, our entire product reducer is ready. Now, there is only action left. So, we will make action. But before that, let's check whether we are getting state everywhere. So, let's check app.jsx first. So, what was to be done to access state? Use select. useSelector for action useDispatch and useSelector for state useSelector is to be used? yes from where it will come? quickly tell me, it has to connect with react-redux ok, so import sorry, why am I importing here? const state will come to you from useSelector suggestion is not available, no problem no problem from react-redux alright, alright, alright So here we need useSelector. Here useSelector is here. And this is your hook. So in this way you have to useSelector. UseSelector. You have to call hook in this way. And not only in this way. Here you have to work in this way. On subscription basis, as I told you in just end. Here you have to pass selector. You can understand in this way that this is a higher order function. And here you are getting the whole state. Here you are getting the whole state. Now if you want, you can return the state by doing a splash in the state. Or you can return the whole state without a splash. So I have returned the whole state. So what will you have in this variable? It will be state. So this is the way to use it. I will console you and show you. CLG. I do state here. And I check here with CTRL-SHIFT-I. ProductReducer is not defined. How can this be? Come to store. Okay, we have used product reducer but not imported it. So import product reducer from dot slash reducer slash product reducer. Okay. And if it was default export, then I can give any spelling. Was it default? No, it wasn't default. Come and see in product reducer. Okay, we didn't export. Leave default, we didn't export. Here we will export named. Okay, we have exported named. So we have exported named. So come here and export product reducer like this. We have imported it and put it here. Now it should work. Now it should work. Look, you have the full details of the product. The whole state is coming. And here it is saying that selector unknown returned the root state when called. So the whole root state is returning you. Due to which there will be a lot of unnecessary render trigger. Now you will not understand this. I will tell you properly. Although if you have seen just stand, then I told you the subscription concept in it. that if you are using one state and one variable, then just take its subscription. Otherwise, if you change it in any of them, then it will do the complete re-rendering. It will do the summary re-rendering. Anyway, if you didn't understand, then forget whatever I said. I will tell you this. We will solve this warning. So, for now, we are getting the state here. Look, the product is coming. The product array is empty. So, the state is coming to us. Very good. Very good. We made the product reducer. State is coming to us. And be careful that you have passed this initial state. Many people do this that they don't pass the initial state. So from where will the state come? Nothing will come. See, nothing is coming here. Undefined is coming. So pass the initial state carefully here. And many people are here else state. I am telling the beginners that if they forget the else condition here. So if you forget the else condition, then by default action is not there. So here type etc. is not matching anything. So you did not give the else condition. State will not return. Now if it will not return, then what will you get here? Okay, so keep all this in mind. And we have passed the initial state. So else condition you have to return here. State. So here you will be getting data. Okay. No condition is matching now. Because action is not made. So no condition is matching. Else state is returning here. So you are getting normal state. If you will not return from here. Then you will get undefined. Very good. As I told you in the theory, we are doing exactly the same. Now, it is important to trigger the action. To trigger the action, I have to make an action. You can make an action here. First, I make an action here. It is a normal function. But because it is connected to reducer and reducer store, it is an action of redux. It is returning a plain javascript object. It has type and payload. You have to follow the syntax. Because you are using a library, it has told you to work in this way, so you have to do it in this way. Although it looks like a normal function. And this is actually a normal function. This is actually a normal function. This function will not do anything if you call it without dispatch. What I want to say, I will tell you right now. So this function has become ours. We have returned type and payload. Suppose we are here in type. Now give this key carefully. If you do not give the key carefully, then the type will not match. And then it will not be here. So we make this key constant. We give that constant here as well as here. And suppose if we change the constant now, then it will change in both places. So we will see that too. How can we optimize it? We will see everything. For now, I had said that a plain JavaScript object is returning, which is doing type and payload. There is nothing in payload, nothing. So, we will export the add to product here. Export. Very good. Now we will call this add to product. It will come here and do the matching work. Really? Yes. On click. Sorry. Make a button first. Click. On click. And here we will call. How will we call? So will we call direct add to product? So see here our add to product has been imported. From where? From product reducer. Okay. And here we have called add to product. So will this work? No it will not work. Why? Because we have called it like a normal function. Now how will it know that it is linked to reducer, attached or not? We have not attached it to reducer. And we have called it like a normal function. Okay. So nothing is going to happen with it. See. Nothing is going to happen. Wait a minute. We have come here and have consoled. If this one is a trigger, then it should be consoled here. Add to product reducer. So let's click. Nothing is happening. How do you know how this add to product will work? Basically, you have to come here and match the type. So you don't have to call it normally. To call it, you have to use dispatch. Where will dispatch come from? Again, it will come from react redux. So here dispatch, sorry, use dispatch. and useDispatch, as we used to navigate, navigate is equal to useNavigate, in the same way, dispatch is equal to useDispatch. So now you have the dispatch function, in this dispatch function, you have to call this addProduct. That's it. Okay. In dispatch, you have to call. Did you understand? Look again. Dispatch, and here you have to call addToProduct. Now when you click here, So it will trigger the action. Earlier it was triggering like a normal function. Now when you click, the action is dispatched. When the action is dispatched, it will go to the reducer. It will go to the reducer. There it will get the state and action. It will match the type with the action. And when the type matches, the work that we were doing there, basically we were doing the console, that console should be printed here. Let's see. We clicked. Look at this. Add to product reducer. That means, that means, This reducer is running. So, the only way to run the reducer is to dispatch the action. You don't have to call like a normal function. You have to dispatch the action. Okay. So, this type of multiple actions can happen. So, we will not make the action here. We will make a separate action folder for the action. Action. I just made it here to explain. So, product action, product action.js and here comes the yellow action. So one action came here, add to product. In the same way, our delete product can be our filter product. Filter product means delete product. And you can make etc etc here. We will also do a project, so all these things will be revised in a repetitive way. Okay. So you understood this much. Now come to app.jsx. So from here, add to product is not coming. It is coming from action. So write add to product here one more time. and it should have been imported but we are not getting suggestions. Import add to product from dot slash from dot slash redux slash action slash product action ok so from here add to product is coming to you and here add to product is not working ok so simply you will call action and your work will be done I clicked it, it is working can't you see it is working Very good. So, we understood the proper sequence. Store, ProductReducer, and Action. Okay. In Reducer, you have both State and Action. Match the type with Action. Okay, what is Payload? Payload. So, whatever you will pass in Payload, you basically pass the details. Like, I have passed M-A-N-A-S in Payload. So, you will come here and see that you can access the details from Action.Payload. So, I am writing Action.Payload here. Action.payload. Action contains two things, type and payload. We have matched type with type, we can take details from payload. So, we have clicked here. See, add to product reducer and we are getting minus in payload. So, what will we use for payload? So, suppose you want to pass some details in the function. Sometimes you pass details. So, if you want to pass details, then you will pass details here and you will send those details as it is in payload. So, we will pass details like this. And these details as it is will be sent in payload. That means, if I don't send details here, then it will be coming undefined. Yes, it is coming undefined. And if I come here in app.jsx and want to send some details in add to product. Suppose I send object. Name, name, M-A-N-A-S. It's done, M-A-N-A-S. So here, I reload again. As soon as I click, then see this, add to product reducer. And here you have, it is coming in payload, object. Because as it is, I have increased the payload to the reducer. There is payload in action, and I have passed the payload to the reducer as it is. So, in this way, your data is flowing here. So, action means, basically, a function which is returning a plain JavaScript object, along with that, it can carry some additional information with it. If you want to send any information to the reducer, then we can send it through action. We will pass payload in action, basically, we will pass details, we will send details in payload, it will reach there through payload. Alright. So we have understood this too. Now that you have understood this sequence, then you are ready to do a lot of work. Really? Yes, really. Come on, let's do a little work. So here we have installed the product reducer. And in the product reducer, now actually I do the work of add to product. So suppose here I want to add a product with on click. And we will add the same product again and again. We will not make anything different here. So const handle click. handle click, or let's say, handle add to product, handle add to product, handle add to product, okay, so we made a function, and remove this from here, and we passed this function, now whatever work we will do, we will do in handle add to product, okay, Dispatch AddToProductAction. We have dispatched AddToProductAction. We have dispatched AddToProductAction. We will send the details here. We have not called yet. We will send the details here. In details, we will give the product name as Samsung and give the ID here. Now we are passing the same data. You can also handle the form. You can handle the form and then pass the data. But now we don't have that purpose. We will do that in the project. Okay. So we are sending this detail in add to product. So we have to put this detail in the state. So how will we put it? So this detail will come here. As a payload will pass. And here you will get payload. Now see how to pass in state. So this state is an object. Look carefully. You have to give it in the same format. This state is the whole object. What is in the object? Product key. So, products. This is what you have. Now, the old details in the products will remain. That means, we have to spread the old details. So, dot, dot, dot. Now, how will we get the old details? So, state, dot, products. Do you agree? State, dot, products. We will get all the old products in it. Okay. So, I have spread the old product here. All the old products. Along with that, I have added a new product here. Now, where will the new product come from? Action, dot, payload. Okay. I didn't have to spread it here. I added a new product. So all the old products are spread and a new product is added here. So you know all this basic JavaScript. And I returned this whole object. So our add functionality is fulfilled. So will it be able to add? Definitely it will be able to add. See I clicked, it was added and after adding, the re-render was triggered. That's why you have this whole product here. Okay. And this console is happening from here. So, for now, you can remove this console or comment. I will remove it as per your wish. So, I will reload. And actually, I will use this data in app.jsx. You can do it anywhere. Like, in app.jsx, I did this work. Suppose, I want to show data in some other component. Let's say, I make a page here in SRC. Products.jsx. Okay. R-A-F-C. And here, I want to show all the products. So we will not focus on rendering too much, we will show it by stringifying it directly. So useSelector and state, we have to take state from here. See this is a simple syntax, this is how you know how to use a function. Here what we have done in app.jsx, we have used it a little in this way. So if you have only one parameter, then you can remove this bracket. And if you want to return directly, then remove the curly braces. Remove the curly braces, then there will be no need to return, it will be automatically returned. So, we are knowing all this in a very proper way. Okay. So, we have done the same syntax in product.jsx. So, here you will be getting a state. const state. By doing CLG. We are doing CLG there. Let's see what is coming in the state. So, we have clicked. The whole product is coming in the state. Okay. So, we can access the product from state.products. So, state.products. Okay. So, this is an object. Sorry. It is an array. We have done this state.products, so there is an array of products. So we can't show the array directly in this way. So we have to stringify it. So json.stringify. Although you can render by doing map etc. You know all this. But I am not going to do that here. So in app.jsx, we will put this component here. The product one. Okay. Very good. So I click here, see the empty area for now. As soon as I clicked, the product was added. Wow! And the rerender has also been triggered. Very good. Then I clicked, see the product was added. It was added, but here, yes, it was added. See, there was one object, below that another object came. Then I clicked, another object was added. Then I clicked, another product was added. We are adding the same product, that's why the same details are coming here. You can do it differently. So when I am changing the state here, And if I reload, this data will definitely be deleted. We will also see how to persist to persist. Alright, did you understand this much? Now let's try to understand this error a little bit. What does this error mean? This error means that you have left the root reducer open. You have taken the entire subscription of the root reducer. That means, wherever you change, the rerender trigger will happen. Let's say in product reducer, not in store, in product reducer, where is product reducer? Here is product reducer. So in product reducer, let's say I make a count variable here. What have I made? I made a count variable. And here I will put one more condition. If action.type is our increment, then I will increment count. What will I do to count? I will increment it. And I am writing a very simple logic for this. return object I will return here. And products etc. will be spread here as it is. So dot dot dot which is the initial state. I have spread the entire initial state. In which to change? Only in count. So what to do in count? State dot count plus one. So I have done plus one. So whenever I change the count, it will be plus one. Alright. It will be plus one. Very good. Okay. What is this? Okay. I gave a semicolon, I had to use a comma here. So this is our proper way of working here. Now we have to make an action for this too. Let's make an action quickly. Let's copy it like this and give the name of this action increment. Increment. Is there any detail in increment? Definitely not. So there is no need for payload here. We will not pass the payload either. And here give the key carefully. The key given there, give the same key here. Otherwise it will not match, so it will not work. So this is the increment here. So now let's call this increment function here. Let's make one more button here. And handle increment. Let's trigger the increment action here using dispatch. Const handle increment. Alright. And here we will dispatch. This must have been imported. Yes, it has been imported. So, by clicking on the Increment button, our Increment file will appear here. is being called here. Very good. And what am I doing here? I am making a use effect. Look carefully. Okay, I won't make a use effect here. Because here we are not using the state. Wait a minute. Insert etc. has been clicked here. Okay. So this is a very simple app.jsx. And here we are using the state. Okay. So here I make useEffect. So you must be knowing that wherever we are using the state, if there are some changes, then the whole component is re-rendered. So here I do CLG, re-render what happened. Definitely if someone changes in the product, then there should be a re-render trigger and I will not apply this. I want that whenever there is a re-render trigger, I should know here. So whenever I change in the product, there should be a re-render trigger. Because I have listed the product here. But if I don't change the product. And if I change the count here. Okay. And here I have given the same name. Here instead of click. I will give count here. So if I click on count. Then also will there be a re-render trigger? Hey. There is a re-render trigger on clicking on count. But we have not changed the product. Basically we are clicking on count. Then also there is a re-render trigger. Because here you have taken the subscription completely. Of the whole state. This is what I was trying to say. I have taken the subscription of all the states. So if the count variable is also changing, then the whole re-render trigger is happening. Change it in any, the re-render will trigger everywhere. Wherever any state is being used, the re-render will trigger everywhere. So for this, you can do this, that you had this state coming, CLG, state was coming, now see here, you had products and count near the state. So if you want, if my re-render trigger is only when the product changes, then you just take the subscription of the product here. state.products like this state.products means you are returning products like this so here you will get products so you just have to put products here that's it ok now see now as soon as I click on count then count will be changed but it will not be re-rendered see I am clicking I am clicking if you are not believing then I will come here and in product action sorry in product reducer I will also console here Increment and state.count. Reload. Re-render is triggered only once. Count is changing but re-render is not triggered. Why is this happening? Because in increment it is concatenating. So count is changing but re-render is not triggered. This is what I wanted to tell you. If you want If any variable is changing, then if you don't have a rerender trigger, then for that, you specifically take the subscription of the state you are using, the variable you are using. Otherwise, the entire rerender will be triggered and the performance will be very low. So keep this in mind. I told you this in the just stand. I told you here too. Okay. So, put it in your heart and mind. Okay. Now here we have done our work with product reducer. We have also attached product reducer. I had said that if we have multiple reducer then what will we do? So let's make multiple reducer here. Let's make one more reducer here. cart reducer.js And same work in cart reducer. export const cart reducer You will get here state, action and something like this we will be working here. action.type if you have here. add to cart, then you return the state in this way. We will not work on this either. I am just telling you that you can make multiple reducers in this way. And here we will return the state. That's it. And you can also make the initial state here. const initial state is equal to cart. And in cart, nothing will happen in the starting. It will be completely empty. Okay. So I have made a reducer. Now I have to I have to add one more reducer here. So how will I do it? So you will think that by giving a comma here, we will add a cart reducer. But this is wrong. Here the create store is taking root reducer first and then you attach middleware etc. So cart reducer is not a middleware which you are passing in the second parameter. So here you don't have to do this way. First, we have to combine the reducer and then pass the root reducer to it. How to combine it? It's a very simple method. You name the combined reducer as root reducer, which Redux actually calls it. Standard is basically practice, you can also name it as combined reducer. So, you have combined reducer. Look, combined reducer has been imported from Redux. In this, you have to pass an object in this way and here you can take product reducer and cart reducer. So product reducer and cart reducer both came and this root reducer that you have got, you pass it here. So now both your reducers are linked here. And you will definitely take this in the key value pair because it is an object, so you can write product reducer colon product reducer in the key value pair. But since I want to keep the key and value the same, I'll remove it. If I don't want to keep it the same, then I'll use the product reducer. Suppose I give it the name product. So, by accessing you, I also have to use the key of this product. For example, I'll show you. Like right now, I'm doing state.products. Now, I won't get state.products, it will give me an error. Okay, you don't have state.products. So, what is it? Let's see. First, let's see the state. What is in the state? CLG state. And here I will tell you about the depth tool. What can you do in this way? Use. Here is the whole state. Let's see. Let's reload. So what is here? There is the slice reducer for key cart reducer return undefined during initialization. If the state passed to the reducer is undefined, you must. Okay, did something happen to the cart reducer? Look at the cart reducer here. We are returning the state. Okay, see here again we have missed the initial state. Okay. So you don't have to do this. Now see here you have two things coming in the state. CardReducer along with product. Why? Why is product coming here? Why is productReducer not coming? Because we gave here the key. See carefully. We gave the key product. If I remove this and leave productReducer, then you will get productReducer here. So you have to pay attention to this. And here you have multiple reducers. And inside every reducer, its state is available. So you want to use cart reducer, product reducer, what you want to use and do it carefully. I have told you the subscription funda. If you are taking the subscription of product reducer, then any variable or key will change in product reducer. So in your entire product reducer, wherever you have used any variable in product reducer, it will be rendered. If you want to take the subscription of product reducer specifically, you want to render there only when the product changes. So, just take the subscription of the product. And how can you do that? So, you can do something like this. Like state dot. Now I have taken the subscription of product reducer. I have taken the product reducer of this. So, here. Leave it here. Let's simply do CLG state. Otherwise, we will have to do JSON dot stringify. So I have taken the product reducer's subscription. So if I change it in count, then also it will be re-rendered trigger. See, it is re-rendered trigger, that's why the product is visible. I am changing it in count, then also it is re-rendered trigger. Why? Because I have taken the product reducer's subscription and there is also a count variable in the product reducer. So if I change it in count, then also it will change in product. So if I want to take only the product's subscription here, then what will I do here? I will use it in this way. Product reducer dot products. Now here you will have only products. See. I will change the count, so it is changing in the count. See, there is no detender trigger in this. Look carefully, it is only changing in the count. So you have to keep all this in mind, that in what way you are taking the subscription, in what way you are doing it, and you have the permission to combine it, that in what way you can combine it, etc. And here, now you have products coming, so let's show the products too. Products. JSON dot stringify products. Okay. So I added it to the product. The product is being added. I clicked on the count. So great. It is working in this way. And there is a slight mistake in the count here. Remove this console. Now there is no need for a console. Okay, so you understood this. If you want to change something in the state, then you have to define the action. It will come to the action reducer and work with you. And something like this will be working for you. Now what else do we have to learn? So now we have to see how we can put a little dev tool here. Because we have I have also seen in the gestion that how simple it was to attach a devtool. Devtool means, here you can install an extension, Redux Devtool, in which you will get this type of icon, with which you can manage the entire state. For now, it will tell that no store is connected. Whereas we have made a store, but we have not connected the store with Redux Devtool. So here also you have, this is the Redux option coming, but it is not connected, so you will not see it. It is not visible. So to connect it, there is a line, which I do not remember. how to connect how to connect redux dap to to redux here you have to come to the side of stack overflow, here you will get it in a very proper way, then see this in the second parameter, have created a story, and here you have given a root reducer, along with the initial state and here They have done it in a different way. What we have done is our proper syntax. And here if you want to attach, you have to activate this DevTool extension. Here you have to copy this command basically. Just copy this much. If you don't want to attach any other middleware. If you want to attach any other middleware, then you have to compose here. And then you can attach your other middleware there. That means come to the store here. And here you have simply pasted this line this much. You can see the whole state in tree format. There is no need to do console. If you change anything, you will see the product in the product reducer. We can visualize the state properly and see everything. Here you can see the add to product action that we have used. You can also see what payload you are sending. So if you make a mistake, you will know that you are sending the wrong payload. Or this action is not triggering. Or some wrong data is going in the state. So this is a very interesting extension. You can download it. It is called Redux DevTool. You will come here and search. Redux DevTool. Because already Redux is a little complicated. It is lengthy. It is not too hard or complicated. It is a little long and lengthy. So you will definitely need all these things. So you can install this extension here so that you can check out the whole state. And if you want to install some middleware, which will need to be installed. If you want to set up a thunk, which will be possible in the project, then I will tell you. Or I will tell you directly in the Redux toolkit. So let's see. So here you By using Compose, where will you get Compose? You will get it from Redux. By using Compose, you can apply your middleware here. And at the same time, you can apply both of these. Your choice. And give a comma here in this way. Okay. So, it will still work. It will not work like this. And at the same time, you can apply middleware here. Okay. So, did you understand this much? Okay. Very good. Okay. So now what to do here? Now everything is proper here. One thing you can see here, what you are doing in this way, here add to product, here increment key and then here also you are doing this way. So if you change one place, then you will have to do it in both places by searching. So for this I will recommend you to make a constant and work. Make a new folder here. Constants name and here product constant, whatever constant is there, keep it here. Product constant.js. Okay? So what did you have here? const addToProduct. This was it, right? Is equal to addToProduct. Okay? So this variable will be our name, addToProduct. And in that variable, we have saved this string. So now we will use this variable. And if we change it here only, then it will change in both places. So this is a better approach, the rest is up to you. We will import from here by coming to action. Add to product, see this. Our import is done and we will use it here. Now don't use it like a string, this is your variable add to product. See this. Okay. Then there is an increment in it, so make an increment here too. Increment and this. Increment. I am telling you all in good practice. In this way, you will actually get it in projects. So now here we have to use the variable named increment. And it must have been imported. So now I will just go inside this variable and change it. It will be updated in both places. Okay. In the same way, you can also do it here in the cart. Like I have made a product constant. Product constant in the same way. Where is it? Product constant. Similarly, make cart constant. Okay. One more thing. When you are combining reducers, not one or two reducers, but many reducers will be made. So, you do this work separately, not in store. So, here you, where is reducer? Here is reducer. So, in reducer, you make an index.js file. Index.js. And by index.js, we also know that this is root file. So, here we will import combined reducers. And here, Combine reducers. We will combine reducers. So first of all. Our product reducer will come. Then our cart reducer will come. Alright. And. It will provide us. In return. A root reducer. Provide. Combine reducer. Provide. And we will export it. Export. Root. Reducer. That's it. Export. Default. Let's do it. Or you can also do named export. So export. Default. Root reducer. Now you come here. And import this root reducer. import root reducer from dot slash reducer slash index.js. So, this whole root reducer will be coming from here. You can remove this from here. And also remove this. So, now it is neat and clean. Okay. All the reducers, you will make reducers in this folder and put them in index.js. That's it. And the rest of the work is happening here. Sorry, it is happening here in the store. Okay. Now, if we want to persist data, what can we do for that? For that, there is a long process. Should I tell you or should I just tell you? Then you will get confused. See, I don't remember all this. So, for this, I will search for Redux persist. Although, I have memorized the syntax to a great extent. Because I have done a lot of work, so I know. But still. Let me show you how to do it with documentation. I searched for Redux persist. To do persist in local storage, like we did in Just Stand, you have to install a separate library to do that. Redux persist. I will come to Redux persist. And let it open. Open quickly. What are you doing? Is our net dead? The net is working. Then what is the problem? So let's install it first. Until then it will keep loading. NPM i Redux persist. Right now our data is getting lost. Whatever work we are doing, our data is getting lost. I want to save it in local storage or session storage. So how will I do it? Like right now we are doing something here. We are reloading. Our data is getting lost. So we don't want this. So how will we do this? So for this you have to do this. Basically you have to do this. You have to pass in the persist reducer and also have to enter the configuration for persist. What name you have to give in local storage or session storage. And which storage to use. You have to use local storage or session storage. So you have to do this little work here. Ok. Here. You have to persist the reducer and also have to put it in the store. So this is the persist reducer. Ok, from where will this persist reducer come? From redux persist obviously. Then persist reducer. Suggestions are not coming. No problem. I know. You also know that it will come from Redux Persist. If you don't know, then you can see from here. It is coming from Redux Persist. Two things are coming from Redux Persist. Persist Store is also coming. Persist Reducer is also coming. So first of all, let's do Persist Reducer here. So Persist Reducer. What things do you have to put in it? I close it for a while. So what things do you have to put in Persist Reducer? You have to put Root Reducer. We have put Root Reducer. Along with that, you have to put Persist Config. Basically, you have to put Configuration. Configuration. What should be the key. What should be the storage. So by putting all these things. Your persisted reducer is made. That has to be passed here. So it is working in a very layered way. First we made a combined reducer. Root reducer was created from that. Root reducer was then put back in persisted reducer. Then persisted reducer is being put here. So a little bit. Length is actually enough. But if you understand in flow. Then you will also understand. And you have to do it a little bit. You have to do it. You have to be a little bit brave. Okay. So this is our. Okay, where will this storage come from? So we have to tell the storage which storage to use. So by default, this is local storage. This is what you have imported from here. And it is important to mention the storage. If you don't do it, then it won't work. You have to tell whether to do it in local or in session. If you didn't do it in just stand, then it would have done it in local by default. But you have to tell here. So, redux persist slash lib slash storage. So, this is basically your default export. So, we are doing default import. And this is local storage. So, by changing the name of storage here, you can also write it local. And this is your storage key. In storage key, you have to pass local in this way. So, this is your local storage. How will you do session? I will tell you that too. So, has it persisted? No. Right now, you have persisted reducer. You have to persist store here also. If you want to persist the store, then all the reducers will be persisted. If we want to persist the product reducer and not the cart reducer, then there is no configuration for you. You can do blacklist and whitelist in the configuration. So I'll show you how to persist this store. So in this way and they have made a function and exported the default. So we can do this by putting the whole story in it. Then we have to do the store and persist story. There is no issue, we do this line, we are doing it properly. So here it is not copied. Look at this. We have put our store in the persist store. Now this is our persist store. Give it the name persister or persist persist persisted. You can also call it persisted store. Now here you have to export both things. Why both? Our persisted store will not work. No, you will have to do both. Export here. Export. Let me tell you why. Here you will have to export the store as well as the persisted store. Why? Because if you come to main.jsx, then you have used the store in the main.jsx, which you have to do. And to persist, you have to use the persist gate in this way. What do you have to use? You have to wrap in persist gate. Persist gate. From where will this be coming? Definitely, redux persist slash integration slash redux. Basically, you are getting it from redux persist. So, you are getting persist gate. You have to wrap it with this. So you wrapped the store, data was being provided, but the data was not being persisted. To persist, you wrapped your application in the persist gate. And here you get a persister prop, in which you have to pass your persist store. Persist store. Now where did the persist store come from? It didn't have to come from here. See, you have to keep all these things in mind, that where to come from the persist store. So it has to come from your store.js. And this default export is no longer there. This is your named export. So from here, store. And we will pass the persisted store here. So now what will be our persist? Definitely. So you understood this much. We wrapped the persisted store from the gate and we passed the persisted store here. Now if you come here and see, then I reload. As soon as I clicked, this data was added. And if I reload now, then the data is as it is. The data did not fly. Wow! The data is as it is. I come to the application and see. So in the application, there is nothing in the session storage. In the local storage, see what is the key here. The key you have is coming from the MyStore side, I have already done it in the JustStand, I have not deleted it. So let's delete it again. So now the data has been removed. So now I have reloaded, see the persist root. Where is the root coming from? So we had given the root here, key root. So if we do MyStore here instead of key, then here, see your key MyStore has come. So clear it for now, reload it again. So see this is the key MyStore. Now whatever data you will save here, your data is being saved in local storage. You will reload, your data will not fly. Okay? Data will not fly. And one more thing you have here, you can tell here, blacklist, whitelist, what I said, you can mention here, that who doesn't have to persist. Like you don't want to persist any specific reducer. Okay? You don't want to persist. So I can blacklist it here. Blacklist. Oh man, black. What used to happen? So I don't want to persist any reducer, I don't want to do product reducer for now. Because we have made product reducer complete, we have not worked in card reducer. So let's assume we don't persist the product reducer, then see the data is over. Now if we put the data here, we will also reload, the data will go away. Because we have not persisted the product reducer. In the same way, there is a white list. In the white list, you can mention which reducers have to persist. All those reducers will persist, the rest will not. Okay, so you understood this. For now, everyone has to persist. Alright. Alright. Wow. I think I told a lot. I didn't think I would tell so much. But... I have told you a lot of things. Actually, I have told you a lot more than theory. There are many more things. There is also thunk, but we will discuss that now. So, a lot of short circuit will fly in your mind. We will discuss that in the project. In the project, all these things will repeat again. So, you will be having fun. You will be practicing. And after that, when we will discuss thunk, you will feel that all the previous things have been revised. Now, if we will take a new thunk seek, then what is the problem? Okay. Or you can direct it in the Redux toolkit. Let's see. Basically, I will bring a project on Redux. and then ReduxToolkit and then ReduxToolkitPickProject will come and then we will do big projects, what is the problem? If you want to use session storage, then how to do it? So this is local storage, if you put slash session here, then your session will be made here. You can also leave the name local because default is being exported. So here I do session instead of local. So this is your session storage. Now it will be saved in session storage. Whatever data I put, clear it with local storage. See, the data is not going to the local storage, it is going to the session storage. And you know what is session storage versus local storage. Okay. You know what happens. In session, basically, if you open this window and open it in another window, then the data will fly away. But in local storage, whether you change the window or not, your data will remain maintained. You can close it anytime, open it anytime, your data will remain there. But in session, if you close this session, then your date will end. It comes, it only comes to you. Still, I told you. So this was your Redux and Redux toolkit. So I hope I told you everything. And it's a little big. And to persist, the configuration that I have done here, you can make it separately. Persist store name. You can make something according to you. But I don't think there is a need to make it. If you work in this, then your work will be done. Okay. So manage in this way. Actions. Okay. Now these actions will trigger you. In reducer, you will come and tell what to do. Right. In reducer, you will do all the work. State is in this. It is very important to return. Then we made constant because in action also same constant was being used. And in reducer also same constant was being used. So suppose here by mistake we changed it. And we didn't change it here, so it will be messed up. So we made a variable. We used this variable here as well as here. So we will just change it here and our work will be done. And here is our store main, which is linked to everything. And then we provided it in main.js. Now we can use it anywhere in our component, anywhere. So... Tell me if you enjoyed it or not. Or if your brain is completely shunned. So this is what I have to tell you. It was a bit complex. I tried to make it as easy as possible. I have tried to make it. Rest, if you are practicing, it will be easy. And if you are watching it like a movie, then it will be a headache by now. By now, you must have put a lot of effort. Okay. But if you have practiced, So, you must have understood properly. There is so much guarantee. Okay, so that's it for now. And I will push this code. See, I will push it in front of you. Data dot. I have added the whole thing. Get commit slash m. This was our redux. And very good. Get status. Now see, it's done. What happened? Status. Great. Okay. And git push origin main. So, I have pushed this in front of you. So, you will get this code. You will get it, right? And there are some more things that I have not pushed. Okay, okay, okay. I have pushed this inside the bit. So, come to the folder outside, inside the react folder. And let's push the whole code. The previous one has also not been pushed. So, git add dot git commit slash all And git push origin main. Okay, so now subcode is pushed. So you will get this code. There is a link in the description. You can check it out. Properly here, basically I have provided a kind of documentation. That too a lot of production documentation. Production grade documentation. So it will be fun to see you. Okay, so that's it for now. And then we will meet in the next lecture or in the next project. Till then, bye-bye.
