Podcast Lookup

Zustand in React Explained – The Truth About Lightweight State Management

ReactJS Developers Podcast

  • December 3, 2026
  • 46 min
  • Episode 11
Episode page
About this episodeIn this episode, we explore Zustand, a lightweight and powerful state-management library for React applications.As React applications…
In this episode, we explore Zustand, a lightweight and powerful state-management library for React applications.As React applications become more complex, managing shared state across multiple components can become challenging. While React Context API and Redux Toolkit provide solutions, Zustand offers a simpler approach with minimal boilerplate and a straightforward API.But is Zustand really as effective as developers claim? How does it compare with other state-management solutions, and when should you use it in a real-world application?In this episode, we examine how Zustand works, its advantages, potential limitations, and why it has become a popular choice among React developers.Whether you're building small projects or large-scale applications, this tutorial will help you understand where Zustand fits into modern React development.What You'll Learn
  • What Zustand is and why React developers use it.

  • Understanding Zustand's state-management architecture.

  • Installing and configuring Zustand.

  • Creating a Zustand store.

  • Managing global state without prop drilling.

  • Accessing and updating state in React components.

  • Using actions to manage application logic.

  • Understanding selectors and optimising component re-renders.

  • Managing asynchronous operations with Zustand.

  • Comparing Zustand with Context API and Redux Toolkit.

  • Advantages and limitations of Zustand.

  • When Zustand is the right choice for your project.

Who Should Watch?
  • React.js beginners and intermediate developers.

  • Frontend and JavaScript developers.

  • Software engineering students.

  • Developers exploring modern state-management libraries.

  • Programmers building scalable React applications.

SEO Keywords

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

Zustand in React Explained – The Truth About Lightweight State Management

00:00—
  1. Speaker 1

    Now we are going to explore Just-N and for this I would like to show you a very beautiful documentation because Just-N's documentation is very simple, neat and clean so you will understand after seeing it. I have also shown you the documentation of the contact API which was very dirty. Basically, beginners will not understand it at all. So, its documentation is very beautiful. If you come here on documentation, you will see its home page like this. And as soon as you click on documentation, a very beautiful documentation opens up. You can understand things by reading here. Very small things are written here, but you will understand easily. Installation etc. and how it can be created. And it is very simple and easy to use. Context API is also there, in which we have to provide the components, and then we have to use it. It has a lengthy syntax, but it is very simple. You have seen the context API, that you are coming directly to just-end. Although there is not much dependency, if you see directly, you will understand, I will explain to you. But still, at least you should know why we use just-end, state management, etc. In sequence, we have state management, context API, and then just end. Next, we will read Redux and Redux toolkit. This is the whole part of state management. So, if you see in sequence, it will be more fun. Rest, if you have some idea in React, props, states, etc., then you will understand. Okay, so, very nice documentation is given. It is very simple. Context API, Redux, Redux toolkit. If there is something very simple, then you will find it just end. Exactly, very simple. There is no problem of providers, etc. in this. Create directly. and use it. So, I will tell you all those things now and I will not tell you by copying and pasting the documentation like this. I will tell you from the start, definitely from the basics. You can read the rest of the documentation. I have shown you that this kind of documentation is seen and you can come here and read it easily. And even you can read a lot. If you are working on Justin in your project, then definitely you will have to explore. Rest, what I will tell you will be more than enough. I will clear you a lot of things which are actually used in projects. So, I will cut it here and come here. First of all, let's understand why we have to use just 10. I have already told you, but still let's understand why we have to use just 10 and what are the problems. So here you will have multiple components like navbar, homepage, about page, footer, cards, pages, loaders etc. The problem is state sharing. If there is a need for the same state in the footer, then how will you use it in the app? You will have to make a state in the app and drill a prop in the app and send it in the same way in the footer. But if there is a need in about and about is in the homepage, First you will make it in app, then in home and then in about. This is how you have to do prop drilling. There is only one option of state sharing, props. Data has to be sent through props. You know that if we want data through props, then we have to take it through props. So to remove all these problems, we make a global state here. What do we make? We make a global state or you can also call it store. Global state or store. Now, by global state or store, it means that all the states will be able to use all the components. And this is the work of Justin. What is Justin's work? To make a global state. So that all the components will be able to use that state. Without any jigsaw. That parents have to take props as a props. Then here as a props, pass to the child. Then he will give to his child. And sibling can't even transfer. First parent will have to give. Then after that, So, for this you can use context api, justend, redux and redux toolkit. And now we are going to make this store from justend. We have seen context api, now we are going to use justend. Now if you understood this much, then understand one more thing. You have seen context api, and if you haven't seen it, then listen to what we were doing in context api. In context API, we used to create context. And then there was an important step, a little complex step of the provider. Provide context. Provide context and then use context. These three parts were used in context. So there you had to create context, provide context that which components you are going to use. And use it. That's it. The most complicated part was the Provide part. Just-and removed it. If you see Redux and Redux Toolkit, there is also Provide funda. But here it removed it. There is no need to provide. Just create and provide the responsibility of Just-and and you can use it directly in any component. You don't have to mention that we have provided this component, this is a parent component, this child component will be able to access. All those things are not a problem here. You will create directly, not a context, basically we can say store here. You will create a store and use the store. That's it. Create and use. There are two simple processes and if you understand these two processes, then your work is done. The rest of the higher level things, I will tell you in this lecture. Don't worry about it. But these two, If you understand this carefully, then everything will be clear to you. You have to create and use. That's it. Keep this in mind. So why is app.jsx open? Main.jsx, close all this. We stay on app.jsx. And here our application is running. Let's check once. So yeah, the application is running. Alright. So what do we have to make? We have to make a store. Here in the src folder, we will make a store.js. There is no need of jsx. Here you have to keep simple store.js. and here you will first import create and create from where you will import actually I have not installed justin so first of all you install justin so npm i justin npm install justin you can write or you can go to the site and do command copy paste from there there is no issue basically you have to install justin so we have installed alright Now you must be getting a create here, it is not coming, no problem, we write manually. So if you look carefully from the just end, then you have one like this create. Create and create store, two things are coming, you have to use create here. And with this create, you can basically make a hook. Hook is returning in return, I will explain to you how. It has a very simple syntax. Here you will write create like this and you can create it as a higher order function. Here basically it is taking a function in itself in this way. Set and get are two parameters. Set and get. We don't need it now. We will see it later. For now, it is a higher order function. We have to pass a function like this. That's it. It is so simple. And here you have to return a state. Which will be an object. Now the object you have created is your state. And you can use this state everywhere. Anywhere. Now how will you make the variables in it? Because it is an object, so you will definitely make it in key value pair. So here in key value pair, I make a variable named counter. And here I make a variable named name, mkl. Just let it be this much. And our state is ready. What did we do? We used create. Higher order function. We gave a function in it. We returned this state. And returning is a must. Because you are using this curly braces syntax. You will see this bracket syntax in many places. This is all part of normal JavaScript. This is not part of React. If you are using this syntax, then you can directly do it like this. Return. There is no need to return. You can directly work like this. Here, count 1 and name mkl. Okay? So, you must know this syntax as well. It's a normal function of JavaScript. It's not React's funda. So, you can make it in this way as well. So, you must know all these things. And you will get maximum places in this way. So, let's leave it in this way. Okay? So, count 1 is done. And name mkl. We have made two variables. And we will see how to do it. In return, this create is providing you a hook. So, let's call it useStore, useMyStore. UseStore is also available from JustEnd, so let's call it useMyStore. Otherwise, naming will get conflicted. UseStore will be available from JustEnd as well as from here. So, it will get confused. So, we have given its name as useMyStore. You can give any name of your choice. I have given useMyStore. Because I know that it is providing a hook in return. And we have to call it like a hook and it will give us state in return. Okay. So use my store. It's so simple. There is not much in it. Now we will default export. Use my store. That's it. We have created it. Exported it. There were only two things. Provide etc. There is no problem. Create. Use. we have created it, now we will use it, so you understood this syntax, create higher order function in this way, and here we have removed the return syntax, we have written normally in this way, so there will be no need to return, this object is your state, and in that state you have count and name, how will you access it as a normal object, so first of all, let's come to the app, let's access the app, so use my store, and call it as a hook and in return it will give you this state. You can give the name of the variable. Let's do CLG and see if we are getting the state or not. So let's come to our project and open the console. So see we are getting an object which has count and name. Count1 and name mkl. Now, you can use it anywhere. It will be your global state. You can use it anywhere. You did it in your app. If you want, you can make a component folder. Components. You can make a navbar file in components. navbar.jsx rafce If you want to use it here, you can use it here too. So, use my store. Call it this way. And see, my import is happening. If yours is not happening, then you can see, you can manually import it according to you. Where will it come from? From store. We have created and exported it from store. So, take use my store from store. Otherwise, if you write use store here, then use store also comes from just end. So, don't get confused in this. Just end use store and what we have made is different. So, here you have to use use my store. Which is coming from store. Which we have made. Okay. So, here you are getting state and here also you can see. This is app.jsx, right? We were in navbar. So, here use my store and from here you will get state. Cons state is equal to and this inside navbar. Let's print it here. We know what is coming. State.name is coming. Something like this. Paragraph state.name and along with paragraph state.count. Okay. So we have printed in this way and now let's use the bar. Let's see if our work is working here or not. So let's do one thing with the bar. Let's put it on top of this hello. All right. Suggestions are getting very good and here we have imported the bar. So let's come here. So look at this. We are getting all these values in the bar. MKL and one which is coming from the state. So we can use it in any component. Simply we have to create a store and use it directly. There is no problem of providers here. So this was the basic basics that we will create and use the store. Now let's do some real work and see how it works. If we change the state, then there should be a rerender trigger everywhere and there should be an updation in the UI. So let's see how we will do all these things once. and it will be fun, there are many more things, I will tell you everything here. So remove the console.log from here, we are not using the state here, and let this navbar remain, and here we have given bg-red for nothing, this is looking a little wrong, let's remove it, so now ours is looking something like this, okay, so remove this hello too, and we are using it inside the navbar, so okay, let's do it inside the navbar, you have to use it in the same way in all other places, So, I will show you in the navbar. Remove the navbar from here. And we only have this name and count. Okay. So, let's come to the store. Now, I want to do plus one in count. Make a function which does plus one. Generally, we do this. We make a state. So, count plus plus, minus minus. And we do different things with this state. So, how can we do that? Let's see. If we try to make changes in the count directly, then we will have to do re-render trigger. So how will we change? For that, I have just told you that here you get a function called set and get. So now I don't need get, I need set. Now if we make some changes in the state using set, then we will have re-render trigger. Like it happens in a normal state, you make a state, there is a set state function, you use the set state function and set it, then you have re-render trigger. Do the same in this way, but it is a little different in syntax. Here you get the set function. Now what is the set function? So you come to the set function in the documentation. It is written very properly and very nicely in the documentation. What is written? So it is written that the set function you have, the set function merges state. The set function merges state. Means the old state merges the new changes. And merge means to understand carefully. Merge means understand carefully. If you have this old state, in which you have name and count. If you have this old state and you want to do some changes in name like this. If you want to do minus in name instead of mkl, then it will not do anything in count. It will only merge the name in the old state. Do you understand? Earlier, it was mkl. Now, we have changed the new one, only changed in name, not in count. So, it is not like the count will be removed. It will merge. It will merge the name here. Name and the old count will remain as it is. Rest, if we make functions in it, they will also remain as it is. Okay. So, it works to merge. Keep this in mind. Alright. So, how will we do it? So, set up has a function. Okay. Set is a function. But here, what we have to do is, we have to increment on a button click. So, let's make a button here. What is the name of the button? Let's give the name of the button increment. Okay. And let's come here and see the increment button has been made. On clicking on it, one, two, three, four should be incremented in this way. All right. So how will we do that? So here we will put an on click and we will do our work inside the on click. Let's make a handle click function. Handle click. All right. And here const handle click. And whenever we are working here, basically clicking, then this handleClick function will be running. Okay. Now here, this is fine, this was a basic work. Now here we have to make a function for the changes. So I give the name of the function here, increment. Okay, no problem, you can give any name. And you have to work in key value pair. So this has become our function. No issue, increment has become your function. And here comma is missed, so let's give comma. So this is now the state part. Okay, count, name and this increment function. Okay, now what will the increment function do? In the old state, it will make the count value plus 1. In the old state, the count value, only the name and increment should not have any difference. So, for that, we will use set. I just told you. So, set is a function. We will treat it as a function. Now here if you want to set it directly, then you can set it like this. There is only one object. The whole state was our object. So here we used the object like this. And here we just have to change the count. So let's change the count to 2. And let's see if our count is 2. So whenever we call the increment function, then our count should be 2. Rest name and all these things should be as it is. Let's see if it is happening or not. So here on handle click, increment, let's do one thing from here, the state is coming, so in the state you must have everything, you can see the state by doing CLG, so here in the state you have the count, the name and the increment function is coming, so state. state. increment you do this way, so this function will run you, so as soon as I clicked on the increment, see this, your state has changed and the UI has also been updated, so the work is done properly, we have used the set, we have set the count value to 2, We have set the count value to 2 and it is working properly. But if we click after 2, then it will not be 3 or 4 because we are setting 2 again and again. So we have to move a little and work. One more thing to keep in mind is that we will not use it in this way in the future. The way to use it will be a little different. We will take the subscription of single single state. Basically, we will take the subscription of single single variable. We will not take the subscription of the whole state or the subscription of the whole store. Subscription means all the values in the state we are using. That means we have taken all the subscriptions together. So we have to take subscriptions one by one so that the performance is better. And what is better in performance, how is it better, I will show you that in a proper way. But for now, we will use it in this way. Increment is working here. Now increment is working, but I don't want it like this. I want this count to be in the old state, that means in this count, plus 1. If it is 2, then 2 plus 1 is 3. If it is 3, then 3 plus 1 is 4. If it is 4, then 4 plus 1 is 5. Like we normally do. So how will we do it? So here we will also need the access of the old state. Now to get access to the old state, you have to use this set as a higher order function. Exactly. Okay? How? So remove this and work like this. So here you get a state parameter by default. And in this state, you have count, name, and increment. This is the whole state. And here again, you use the curly braces syntax. Or normally do it this way. If you do the curly braces one, then you will have to return. And I don't have to return. So now I want to change the count in the object that I am making. Now what changes do I want to make in the count? So the old count, state.count. In this state, you will get count, name, everything. If you want, you can check out. I can show you. Let me show you. This state. And now let's use the syntax of curly braces. And return the entire state. Otherwise, it will be undefined. And if I don't return anything, it will be undefined. It won't be able to merge anything. So let's do CLG and see what is coming in our state. And we have also done it somewhere in app.js. So let's remove the console from here. Let's reload. So as soon as I clicked on increment, see what is coming in the state. Count, increment and main. So we are getting the old state from here. So what do we have to do in the old state? In this way, we just have to do changes in the count. What to do in the count? State.count, which is the old state, we have to do plus one in it. And this It will take a comma here. Even if it doesn't take a comma, it will work. So it will merge in the state of count. And the rest will remain as it is. So our count will be 1 to 2, then 2 to 3, 3 to 4, be 1 to 2, then 2 to 3, 3 to 4, 4 to 5. Come and see here. We have incremented. 2, 3, 4, 5, 6, 7, 8, 9, 10. Okay. The rest is as it is. Name is as it is. All this is as it is. So, something works like this. And you will not get syntax like this. You will get syntax like this. Here, count and state dot count plus 1. So it's up to you, if you want to use the return syntax, this one is better. So this is how you can work. So we have created an increment. So the increment is also working. If we click on increment, then the increment is happening. Alright. So this is the work of set. Now let's see the work of get. The work of get is very simple. Let's say I work on name only. Let's work on name only. I will create a function here, ManipulateName or CapitalizeName. As soon as I click on it, it will capitalize the first letter. Although it is a full capital, so let's make it small. So now it will capitalize the first letter. How will it do that? Will we write logic for that now? What is the problem? So now we are using the set function here. We were using the set function, so we were getting the whole state, and we had to change the count in the state, we changed the count. Now let's do it a little differently, we will use get here. So let's use set to set, let's use get to get. Okay, so let's use get, I'll show you, I'll do CLG, get, and get is also a function, so normally I called it. Now see what will happen, whenever I call this function, capitalize name, and here we have to make another button. handle name click and here I write capitalize alright and here we have to make a function handle name click pause handle name click very good and state dot state dot capitalize name ok very good so what will capitalize do First letter will be capitalized. We haven't written the logic yet. Let's see what happens when we click on capitalize. See, the whole state has come. That means, we can take access to the whole state by using get. Exactly. So, what will I do here? I will destructure the name here. Is equal to get. What did I do? I destructured the name. You have multiple things, so you can destructure multiple things here. In the gate, I was getting all the things, there was an object, so I destructured it and took out the name. Now whatever you want to set here, you can simply use set here without using the higher order syntax. You can set it directly here. For example, I want to capitalize in name. So the old name, this name, I want to work with this. So I will write here name.careAt. You know how to capitalize, right? Basically, we have to make the first letter capital. So, I have made char at 0th index. What is m at 0th index? So, I will convert m to uppercase. To uppercase. This is all basic logic. If it is not coming, then take a chance. Rest, you have not read javascript. This is your problem. So, I can't do anything. I have told you all these things many times. I have also made you practice. So, here we will convert name.char at 0 place to uppercase. And rest of them, as it is, we will paste here. So, we will concatenate. Okay? Now, how will the rest of the things come? So, the rest of the things will use the name.slice and will pass here one index. That means, from one to the last, whatever will happen, like m, k, l, I write the whole here, minus Kumar Lal. So, here m care at zero came and I converted m to uppercase. After that, the name.slice will slice from one to the last. Okay, by slicing and we have concatenated. So, the first letter is capital and the rest of the letters as it is here So we have set the name as well. Let's see if it is working. Let's reload it. For now, it is in small letter. Look carefully. It is in small letter. Let's capitalize it. Wow, it is capitalized. So in this way, you can see here, you got the one using GET or you got the one using SET. So if you got the one using any of them, if you are making it by yourself, then you will work according to yourself. You can also use SET or use GET to set it directly. And you have a lot of different scenarios, you should know everything. So, this is how we work here. Now, this is not all, there are more things here. So, if you understood this much, then normally you will work in this way. Generally, what do you do? You make a state, there you need a data, which you render everywhere. Okay. And one is set data, by which you work to set the data. And re-render trigger happens only when that set data is used. So, here also, in the same way, this is your normal state, the data, and these two functions that you have made, you have used the set in it. Now, if you have used the set, then whenever you will do some changes there, it will do the re-render tree. Now, in re-render, there is a very good, very strong scenario here. What is the scenario? You have to see that carefully. Okay, understand carefully. So, I am here. I will console the state we are getting. Let's remove the console from the rest of the place. Here it is not being consoled. So by clicking on this increment, I am changing the count. And by clicking on capitalize, I am changing the name. So the count is changing on the increment. The name is changing on the capitalize. Only one change is happening at a time. Either count or name. Now understand carefully how the re-render is triggered here. This is very important. Otherwise, you will down the performance of your application. So here I had said that I have taken the full subscription of the state. I have taken the full subscription of state. So if I print state.count only. I have printed state.count only. And I am not even making any changes in count. I am just changing the name of the string. So I clicked on capitalize. So this change happened but this was re-rendered. You can understand what I am saying. I have changed it to name, but re-render trigger is also in count. That means, re-render trigger is happening everywhere. If you want, you can destructure it. Here you are getting count. Assume you don't want to take name. Okay. We will not re-render name here. We don't re-render name here. And here, okay. We are doing count only, increment. And this is all fine. Count. And here, we we have to find the increment function and also the capitalized name function. Try to understand a little carefully here. Alright. So now we don't need to do this state.increment. We have done the restructure. Remove it here too. So directly we can call here. Direct increment pass here. Direct capitalized name pass here. What is the need to do this much? Remove it. Okay. So it is very simple. Increment on increment, capitalize on capitalize, and the state that I have used is only of count. Only of count, not state.count. Only of count. Okay? Like this. So now, state is not defined. Alright, here also state is there. Okay? No issue. Let's reload. And do one thing, not like this, make useEffect. Right? and here do CLG, re-render what happened? ok, re-render what happened? by this you will know whether the re-render is triggered or not and the rest count variable if you want to see then you can see that also so you know whenever re-render is triggered then only this use effect will run so here I click on increment so definitely re-render is happening because we have used increment here basically we have used count so here increment is happening and re-render is also getting triggered but if I click on capitalize Even then, the rerender trigger is happening. While I am not even changing the count variable. I am clicking on capitalize and it is changing the name variable. We are calling another function there. Because it is not changing anything in the name variable. Even then, the rerender trigger is happening. That means, here we have All over, the whole store subscription has been taken. So if we do changes in any of them, then the whole re-render will be triggered wherever the state is used. The re-render will be triggered everywhere. So the performance will be very low due to this. So keep this in mind. Wherever you are using the state, just take the subscription of that. So that only when it changes, the re-render will be triggered. When the change of the other state happens, it will not be re-rendered. Okay, how can we do that? How will we take only its subscription? For that you get a nice syntax. You don't have to use this type of syntax. Here you have to use the syntax count is equal to. You can give the name of the variable. And here directly use my store. And you have to use the higher order function like this. How? So state. Okay. This is how your higher order function works. So state. and here you will get all the state, but which one to take the subscription, then you have to take the subscription of only count, so state.count, and I have not used the return syntax, I have given it directly that there is a single line, then the work will go, otherwise if the return one is put in curly braces, then it will have to be returned, otherwise it will happen in this way, okay, you can remove this too, if you want, then state and state.count, so only I have taken the count subscription, so if, if, if, okay, all the other things have been removed, then here we have to remove the rest in this way, functions in this way. So, I take the subscription of the increment function and at the same time I can take the subscription of the capitalized name. Okay. So, here you have increment and here the subscription of the capitalized name function has come. Alright? And if by chance, by mistake, you use this syntax, just to destructure the count, then also it will give the subscription of the whole state. You will get the subscription of the whole store. So, keep this in mind. If you use this syntax, then you will get the subscription of the whole store. Even if you do not do one restructure. So, keep this in mind. So, I have destructured the count here. Basically, I took the subscription of the count, took the subscription of the increment, and took the subscription of the name. Okay? Now, see what happens here. Now if I click on increment, then re-render trigger is happening. That's good. But if I click on re-render trigger on initial loading and on capitalize, then re-render trigger is not happening. It's not like the capitalize function is not working. It is working. I can show you. The capitalize function is working. CLG. And here I can use get to show you the change in that state. See, I clicked on capitalize. Now see, this is the old one. But if I do it one more time, then see, it is capitalized. So it is working. But it is not re-rendering. If I click on increment, it will be re-rendering. We are not using useEffect. But if I click on capitalize, it will not be re-rendering. Why? Because we haven't taken the subscription of the name variable of this state. We have only taken the subscription of the count, increment, and capitalizedName. So this matters a lot in JustAnd. that whose subscription you have taken. The state of which you have taken subscription, on its change, there will be a re-render trigger. And on someone's change, there will be no re-render trigger. But if you have used that syntax, directly use my store and bracket, and you are taking the entire state, or by doing curly braces, doing only one destructure, that means you are taking the entire subscription. So, if you change in any state, you will see changes in all. Basically, the entire UI will be re-render. Change in any. So this much is clear. The rerender funda is clear. If it is clear, then it is very good. Not rerender, basically it should be called subscription funda. Choose subscription of state carefully. Okay. This is a note for you. Choose subscription of state carefully. Keep in mind how you are taking subscription. Okay. What are the other things in Just Stand? There are a lot of other things. But I will tell you the other thing that I think you should be able to use. You can use middleware in the middle. What does middleware mean? Middleware means if you are incrementing and reloading, then your data is being deleted. Data is getting finished. But in just-end, you get such facilities that you can persist the whole state, either in local storage or in session storage. Okay, how? So here you have to put a middleware. This whole function that you have used, cut it from here. And here in middleware, you get persist. Persist. Persist. Persist is not available. It comes from just-end only. I don't know why. Let's see. Persist. I am not getting suggestions actually. It comes from just and slash middleware. Just and slash middleware. Ok. You should get persist from this. Ok. I was not getting suggestions. Rest is persist. Although you may also get suggestions. Sometimes you get suggestions and sometimes you don't. So persist. Ok. So you have to put one middleware. Persist. And inside it. Now you were giving the whole function on create. You have to give it here. So I didn't do much. Look carefully what I have done. Look carefully what I have done. Earlier you had something like this. Something like this. I said that whatever you are giving, the whole function in create, remove this and put a middleware in the middle. Persist. Now you won't get it. I basically have to put middleware here. You have to import persist. Only then you will get it here. So persist and pass the whole thing here. So will it persist now? Yes. In which will it persist? Local storage, session storage. So by default, it is doing it in local storage. I can show you. See, I clicked on increment. Alright. I reload. Is the data the same? Is it the same? I am clicking on reload. Is the data the same? Is it the same? Wow. This was fun. Local storage, session storage. Separately, that set item, gate item is not required. Here, you will simply use persist. Rest of the work, it will do. Rest of the work, it will do. This is fun. You can come here in application and see. You will come to the application. In the application tab. So here you have. Session. Not session. It will be in local storage. See this. So here you have. In my store. This whole data is available. Wow. Now I clear the whole data. From somewhere else. Some data is coming. So I clear the whole data. I reload once more. So now there is nothing here. One is there. I click in increment. And I reload. So see this. You have here. Undefined. Why is the key undefined? Because we have not given any name to the store. I am reloading. So this data is as it is persisted. But the name of the store is undefined. Because we haven't given any name to the store. So actually persist is taking two parameters. One is that you have passed the entire function. Okay. You have passed the entire function. And after the function, you have an object parameter taking this. Okay. So we have passed this function. Carefully, you are understanding the syntax, right? I will clarify it more. Don't worry. Just look carefully. For now. I will give you more clarity at the end. So here you had the entire function. There are two things here. The first is the function and the second is the object where you can mention the name of your store. So I mention my store in the name. And in the first one, I will pass the whole function. There are two things in persist middleware. You have a function and you can pass the object and you can do some settings here. For example, your name should be my store. So now let's reload, see the data has been deleted, why? Because it is undefined data. Now I will click on increment, so here you have it in the name of my store. Let's delete and here also delete and reload. So now the data is finished, I am incrementing, so see this. My store is key and in value you have the whole state. What was in the state? Count, name, etc, etc, whatever it was, everything is coming. Let's reload, wow. Did you enjoy it? It would have been fun. Definitely good. So this was saved in local storage. If you want to do it in session storage, then here you get more settings. You have an object inside the object. As far as I remember for now, you have a storage key. And in this storage key, you can tell here with the help of create json storage, which storage you want to use. Local storage or session storage. So here, I will say that I have to use session storage. This is the syntax. This is how you have to do it. How? Create JSON storage. And this is how you can tell here which storage you have to use. So I have to use session storage. I don't have to use local. I have to use session. So now let's remove the data from here. Now let's see in which it comes. In local or in session. So now it is not in local. And not in session either. There is no data in any. Okay. So let's see in which data is stored. So I reloaded. Basically I incremented. And here there is no data in local. but if I am reloading, then there is data not in local, but in session so we saved it in session storage so these are some parameters, you can see in documentation when you will need, you will go there, search, query basically what are these things available in just end the most important thing I have told you one more thing is dev tool you can also put a dev tool in between like this is persist, so you can remove it from here to here And in the middle, you can put a dab tool middleware. Dab tools. Now, what happens with this dab tool? With dab tools, you can see the whole state visually. Okay, what does visually mean? It means, here you install an extension. This one. Its name is Redux dab tool. You will search here. Redux dab tools extension. Okay, so here you will get Chrome dab tool. This is the one, I believe. Yes, this is the same one. So here remove from Chrome is coming because I have installed it. You can install it here. So you will get this extension. Now this extension does not work directly if you have not set it. If you have not installed the dap tool. Although it is for redux but it works in just 10 and in other things too. Basically you have set up the dap tool. So here we have used the middleware of the dap tool. So that's why it is working. If I remove this dap tool middleware. So I reload. So see this. Something different is coming. Here it is not coming basically. I will open localhost again and let's see what's coming here. So, for now, nothing is coming. No store found. Why? Because we have not installed devtools middleware here. So, I will install devtools middleware. Now, you are getting the whole state's visual information. Here you have count, name, and you can see in the chart that it is a state, it is a count in the state, it is a name, if you make something in the name, then it will also be visible to you visually. Now you can trace everything here, how it is working, who is dependent on whom, you will know everything here. So this is your responsibility, how will you explore all the things. Okay, so I told you everything here, and here you can make a little simpler syntax, how can you make it. So this function, this whole thing, from where to where, I am confused myself. Okay, so do one thing, this is the blue bracket, right? Blue bracket, find out which is the blue bracket here. First of all, this blue bracket has come, then the yellow bracket has come. So this blue bracket, yellow bracket, and then after that, you have this one bracket, this one. So up to here, I believe, this is the whole function. So, you can find it. Don't write it like this. As I got confused in debugging, you may also get confused. So, don't do it like this. Make this function separately. Make the whole set get separately. Give its name as store. Okay. No issue. I have given its name as store. And you can put this store here. Take this. Okay, the one given like this will also not work. Remove this too. Is it ok? Is it perfect? Is there any issue? No. So here, in persist, there were two parameters, store and an object. So here you can give a store and an object. Great. Let me show you one more time. See this. Create. Here you have to put middleware. So let's assume you have to put devtool middleware. So you have put devtool. Devtool. Alright. Now let's assume here you have to put persist middleware. If you don't want to put persist, you can pass store directly here. You can pass this store directly if you want. You don't have to use the persist middleware, but you have to use the depth tool. So it will not be persist. Let me increment. So it is not persist, but you are able to use the depth tool here. And if you also want persist, then remove this from here. Persist. And here is store. And along with that, it has another parameter, which is object. And in this, you can mention what your name should be. And basically, what you have to give in the key that will be saved in local storage or session storage. What name do you have to give? So here I give name, my store. my store and here you can tell me what you want, what you want, what you want, so I just need this much, okay, let's reload, so I'm doing increment, I'm reloading, so as it is, it is persisted and you can see it in the application, so by default it will be local, so this is coming in local and this old data is coming in session, so you can delete it, okay, and I'm incrementing, so it is being saved, I'm reloading, it is persisted, so this is the app's just end and I hope you understood it properly, There is not much in it, you can do a summary here. I can give you a summary here. And the summary is very simple. The first point is that you have to create here and then you can use it directly. Very simple. You have to create, you can use it directly. Okay. Second. To set, to do, you use the set function here and to get, You use the get function. Okay. Third. Subscription. Subscription. Subscription. Is. Directly. Dependent. To. Rerender. So. Subscription. You have to take care. Which state. Subscription. You are taking. Okay. Whichever state. Subscription. You will take. There. Functional way. Mention. That. I am taking. Subscription. Of this state. Subscription. Do not take. Subscription. Of the whole store. At once. Write this too. Don't take the whole store subscription at once. Performance will be down. Alright. And fifth, you can use middlewares. In which you have a persist middleware. Middleware. to save data into local or session storage. After that, you have dev tools middleware, so that you can see the visual representation of state and actions. Okay, so this is your just end and this is your summary of just end and you have a lot of things in it, you can explore it definitely. So simply you have to create it and you can use it anywhere and you have to keep all these things in mind. You can make multiple stores, it's not like you can make one store and all the work will be done on one store. Multiple stores are also created here, so you can make multiple stores too. And in the future, we will see how and how things are used in the project. And in the project, actually, you will get to know a lot more than what we have studied so far. Different different libraries will be coming in your project. And different different things, different different ways you will be getting to use. Okay? So whatever you are reading, this is theoretically still and also practical. I have shown you by using it. But you will be getting a lot more in the project. You will be getting different different ways, which is more important in coding. Alright. So, that's just the end. And I hope you enjoyed it. This is our store. It might look a bit complicated. As more functions are there, it might look a bit more complicated. But it is quite simple. You must have understood this much. Okay. It is quite simple. There is a lot of problem in understanding it syntax-wise. But if you understand syntax, then the rest, Redux and Context API, it looks much simpler than all this. Create it, use it. There is no problem with providers. Okay. So, that's it for now. And keep exploring. And we'll meet in the next lecture. Till then, bye-bye.