Podcast Lookup

React Context API Explained – Master Global State Management and Build Better React Applications

ReactJS Developers Podcast

  • December 3, 2026
  • 42 min
  • Episode 7
Episode page
About this episodeIn this episode, we explore the React Context API, a powerful built-in feature that helps developers manage and share application state…
In this episode, we explore the React Context API, a powerful built-in feature that helps developers manage and share application state across multiple components without unnecessarily passing props through every level of the component tree.As React applications grow, managing shared data can become challenging. Passing props through deeply nested components, commonly known as prop drilling, can make applications difficult to maintain.The Context API provides a cleaner way to share data such as user authentication, themes, preferences, and application settings across components.You'll learn how Context API works, how to implement it using createContext and useContext, and how to use it effectively for better state management.What You'll Learn
  • What the React Context API is.

  • Understanding global state management.

  • The problem of prop drilling in React.

  • Creating contexts using createContext.

  • Understanding Context Providers.

  • Accessing shared data using useContext.

  • Managing application state with Context API.

  • Building reusable context providers.

  • Using Context API for authentication and theme management.

  • Context API versus Redux Toolkit.

  • Common Context API mistakes and performance considerations.

  • Best practices for efficient React state management.

Who Should Watch?
  • Beginners learning React.js.

  • Intermediate React developers.

  • JavaScript and frontend developers.

  • Software engineering students.

  • Developers interested in global state management.

  • Programmers building scalable React applications.

Transcript

From the publisher

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

React Context API Explained – Master Global State Management and Build Better React Applications

00:00—
  1. Speaker 1

    Now in this part we are going to discuss context API and many people were waiting for context API even just and redux, redux toolkit and all things are waiting for it. Because it is very important that all these topics are used in big projects without using them to make big projects. It is very difficult. So, definitely, in all the big projects, all these things are used. And people find it very confusing. I don't know why. It is very simple. But still, some concepts are not clear. Because of which, it seems very confusing. But it is not that confusing. Now when you will see, all the things will be clear. But why do we use Context API, Redux and Redux Toolkit? You should have an idea of it. If you have faced that problem, then you will be using it, then it will be more fun. And where have you faced all those problems? You must have faced it in the previous lectures. When we are making projects, means all the projects we have done in the previous lectures, we have learned small projects. So, in those, we faced some difficulty of prop sharing. Basically, data sharing, which we used to do through props. So, I have told you all those things in the lecture on state management. Just in its previous lecture on state management. You will get to know why you should use context API. I will tell you context API properly in this part. But if you look at state management, then context API which we are going to discuss now, you will get to know why we use it. Also, everything is similar. We use Redux for same state management. Then Redux toolkit. Redux toolkit is also used for state management. If you will use just-and, then just-and is also used for state management. So, after context API, we will read just-and and then Redux and Redux toolkit. This way our sequence will run. But all the things that we are going to use, we are going to use them for state management. So, keep in mind that you have a lot of idea about state management. What is actually state management? Why to use it? What were the problems? In short, I will tell you a little bit. After that, we will go to the proper code, we will see the syntax, and I will also tell you how to optimize the production code. That is very important. Understanding context API is not a big deal. You will understand if you watch the lecture in any way. But how to write in an organized way, how to handle it, because if the code is not big, it can't be optimised properly, that's why we use all these things. So that's very important. For now, let's understand why to use it. So, I gave an example in the previous lecture that if you have a component app.jsx and it has multiple components, there can be many components. Let's assume that A is a component and B is a component. After that, there are nested components like C, D, and in B, you have E, F. This is how your structure is. In a very strange way, your structure can be any. For now, I am telling you as an example that in some way your structure is like this. In app.jsx, there are two components, a, b. And in a, there is a component c. In c, there is a child component d. In b, there is a component e. In e, there is a component f. So, the problem is that if you want to use state in it and you want to use same state in it. Same state. Suppose count and set count is there. So, you want to do set count here. and you want us to show the data here, like we are rendering the count variable here. So, both of them need the same state. Now, how will we use the same state? To use the same state, we will have to make data here, we will have to make state here, and then we will send it to child, then we will send it here, then we will send it here. And similarly here and here. So you have to do a lot of prop drilling. You only need data in this and in this. Same data. You need the same data in this and in this. But in vain, all these components are involved. That data is being collected. So it doesn't make any sense. So the solution for this was that we will make a global state. And by making a global state, whoever will need it. F will need it. F will take it. E will take it. E will take it. C will take it. C will take it. Directly. Okay. Direct. No dependency on anything. It will take whatever it needs from the global state. So, we will make a store in a way. We will make a shop. We will make a store. Whoever needs it, will take it from the store. So, we are going to use Context API to make this store. Okay. So, we are going to use Context API to make a store type. Context API. So that, whichever component needs that data, that data can go there and take it. Do you want to say this? Exactly. This is what we are going to do in this lecture. Okay. So, now let's understand what to do in Context API. We have understood that we will make a global state. From there, all the components will be able to use that state. That's why we have to use Context API. Now, how will we use Context API? How will we do it? This is the most difficult thing for people. How will we do it? How will we keep the code? What will we do? So, first of all, basic. Leave optimization and all. First of all, understand that things will be in three parts. In how many parts? In three parts. In the first part, we will create context. Create context. Before using, we will create. That's why we will use. Create context. Alright. We will create context. And to create context, you have a create context hook. Okay. Hook is there. Create context hook. So, we will use it to create context. Alright. So, we got hook. We will create. No problem. Okay. We will create. It is very simple. Use hook to create. Okay. Then, in the second part, we have to provide the context. So, the create context that we have seen, you can understand that it has become your store. It has become your global state, a store. Now, we have to use it in all the components. Basically, we have to provide it. Whatever data you make, variable you make, state you make, you have to provide it in all the components. This was our aim, that we have made a store, all the components can use it. So, how will we do it? We have to provide it in all the components. So, we have to provide the second work. So, we have to Provide karana hai. Kya karana hai? Provide karana hai. Bas ye 3 steps yad rakho. Context khatam hai. Aur kuch nahi hai yahape. Step wise agar samjhoga, bahut asaan hai ye. Provide karana hai context ko. Provide context. Cheek hai? To ye jo bhi context humne banaya hai. Maal lo, iss context ka naam de deta hu main. My context. Iss context ka naam hai. My context. MC nahi likhna chahiye. M context. Cheek hai? MyContext. So, this context's name is MyContext. Now, what we have to do is provide the context. So, we have to provide this MyContext. So, we will provide it. So, it will be a simple syntax. MyContext, whatever we have made, dot provider you will get here. So, we will provide it with this. Okay. Now, how will we do it? We will see that later. So, we will provide it here. Alright. After that, what is the third step? Provide. See, we have created a context. We have created a store. We have provided. Whatever we needed, whatever data all the components needed, we added that data. We added data and provided all the components. Now what is left? Now what is left is how the components will take that data and how they will access it. We have provided. We have created a store. We have provided. Now the components also have to access the data. So this will be the third task. What will be the third task? Use context. Use context. Okay, understand this. This is important. Rest, there is nothing in the code. It is very simple. Use context. So, for use context, you get a hook. Use context hook. That's it. Use context hook. That's it. That's it. These three steps and use context, context API, whatever you call it, are over. Create context. For that, use create context. Provide context. Basically, whatever value you want to put in it, by putting value, You will provide that value in all the components. Which all components you have to provide, that will be decided from here. Which all components you have to provide. If you have to provide in all the components, then also you can provide. If you have to provide in one component, then also you can provide. It will be provided from here. Then using the use context, all the components that are required for that data, they can use it. That's all. Create context is create, provide is use. Okay. There is no problem in create, there is no problem in use. Let's see how to provide and how it works. The problem is in the second step. The second step was ours. Trust me, I am telling the truth. There is no problem in the first one. It is very easy to create. Provide, you will have to see a little, in which way to provide in which component. So, the scenario of providing here is something like this, that if you have app.jsx, In app.jsx, if you provide the full data, then all the components in it, basically in app.jsx, you will keep all these components, nap bar, card, product page, all the pages will be kept in app.jsx. And some components can be inside all those components. Indirectly, they are inside the app. There will be some components inside the app. Suppose here I say there is a component of nap bar, there is a nap bar, and then there is a home page here. And then let's assume that there is a product page and let's assume that there is a footer. Now there will be more components in it. It can be in home. There are multiple components. So indirectly, this component is in the app. That component is in it. Basically, there is a child component. So if you provide this data to the app, then the app will provide it to everyone. If you have only provided the home, then that data will not be able to access the navbar. The app will not be able to access it. The footer will not be able to access it. The children inside the home will be able to access it. So, keep in mind that who are you providing the provide to? The components you wrap inside that provider, those components will be getting that data. Okay. Wrap? Yes. Like you have read React Router, right? So, in React Router, you will see that the old syntax was Browser Router. So, in the Provide, where we used to wrap all the components, we used to make a route. In that, we used to use NavLinkVTC etc. Leave it. If it is not coming, leave it. If it is in your mind, then you can relate it. So, here we have to make Provide in this way. Suppose, you have made MyContext. MyContext.Provider. Provider. Okay. This has become a component. Now, in this component, this is a Provider component. Okay. Here also, you have MyContext. Provider. Provider. Okay. Like div, you have paragraph, anchor type. Similarly, it is the same way here. You opened it, closed it here. Provider opened, provider closed. Now, whatever components you give in it, that data will be accessible in all of them. Okay. Whatever you give in it, if you give home, then all the child components of home and home can access that data exactly. If you put app.jsx in it, put the app component in it, If you put the app in it, then all the components in the app can be accessed by the provided data. Here we will provide the data, we will see how to do it. So you have to understand that you have to create, provide, and at the same time you have to keep in mind who to give data to. Whatever you put in it, everyone will be getting data. Along with that, all the child components of it, everyone will be getting data. Whatever data you want to provide, alright. Then after that, using it is very simple. Whatever was there to provide, and providing was also not very complicated. You just have to keep in mind that whatever child component you wrap in it, whatever component you put in it, that component and all the child components related to it, everyone will be able to use that data. That's it. And theoretically, whatever was there, is finished. After that, we will do code. Come quickly. So this is our app.jsx and I have installed Vite. You can install it too. If you want to learn it actually, otherwise you won't understand anything by looking at it. You will understand only the theory part, you will understand the code too, but then you will forget. So let's do it together. So what do we have to do? Here is our app.jsx. Suppose I have made multiple components here. I will make a components folder only. Components. And I will make a very simple component. I will not complicate it too much. I will make a.jsx. Then I will make b.jsx. Then I will make c.jsx. And let's make more. Let's make e.f. c.d.jsx. Then we have e.jsx. And then we have f.jsx. Okay. Now let's add content to all of them. RAFCE is our A. RAFCE is our B. RAFCE is our C. This is our D. This is our E. And this is our F. And I have set up Tailwind. Tailwind I believe I had installed, but not set up. Okay, let's come to the browser quickly. Tailwind. Tailwind CSS. I have installed it, I think I forgot to set it up, so here I installed it, I also installed it, after that I forgot to put it, so let's put it here, and all these things are coming to you, you have come to the context API, it is not coming, it means that you are not following the list properly, or wherever you have studied, you have not studied properly, so here we have tailwind css and we have to import css from here ok so here in index.css we will import from the top ok so now our tailwind should work and close it this is our f good remove this and our f is done f e d c b a And this is our app, okay. So the app component is our app component. So let's make a little structure so that you know what is inside. You will get clarity in understanding. Rest you can understand without designing. But just for clarity, which components are inside and what we are able to use properly after making context. Everyone will know that exactly. So now the context API portion has not come. I will show the context API portion now. I will show you slowly. First, let's style it. Let's use the class name here. Let's give it BG red 500 and padding 10. And reload the window. Because I am not getting suggestions. And suggestion is very important. Right? So, now we should get suggestions. Look, it is loading. Yes, we are getting suggestions. Okay. So, here See, we have an app. Let's zoom in a little bit. This is our app. Let's import more components inside the app. Here, we will get A. A. And let's bring B as well. B. It came like this. Let's import A and B. Import A from dot slash component slash A. And here, we will get B. B. Okay? Here, we have B. So, A and B are inside this app. Okay, look at this, A and B. And we'll style A and B a little bit. Class name, BG, a little bit like this. And padding of 10. So, look at this, this is A, which is inside the app. And let's take B as well. Where is our B? This is A, right? Come to B, this is our B. And here, class name. Give it something like this. Take this one. And give padding again of 10. So, this is our B. There is A and B in the app. There are two components here, A and B. Okay. No problem. It should not happen till now. Now, inside A, inside A, inside A, we will keep two components. A is also done. Let's keep C and D inside A. Okay. So, here C came. And here D came. Alright. So here we will also import. Import C from dots less C and D. D. Alright. So here C and D. These are two components. So inside A there is C and D. We will also style this a little. Let's come to C. Class name BG. Give some green type. This is done. And give it padding of 10. So this is done. Your C. Okay. And come to D. Let's do D too. So you guys do it quickly. So it will be a little better to understand. Clarity will remain. Class name. And BG something here. In orange. No. Give something in yellow. Yellow is also done. Try in blue. BG blue. And 500. And padding of 10. So now see. In the app, you have two components. This is the A component and this is the B component. Then in the A component, there are two components, C and D. Okay? You can see the clear cut. Now, let's put two components in B. Where is B? Remove D. Remove C. Remove A. Here is B. We will get two components in B, which are E and F. F. Alright. And let's import this too. Import. from dots less e and import f from dots less f hmm so b contains e and f and here is our e let's style it a little bit just a little bit let's give it bg gray something like this and let's leave padding 5 let's make it a little small component and in f also something like this className and bg. Select any random color from here. Let's take this color. And padding 5. So, these two components are in B. So, this is our structure. In app, there are two components A and A. Then in component A, there are two components C and D. And in B, we have two components E and F. So now we have to create such a global state, so that everyone can get data, the app too, A too, C too, D too, B too, E too, F too. Otherwise, we have to crop drill. Make data in the app, then send it to A, send it to B, and then send it to A to C and D, and then send it to B to E in the app. We have to work in this way. But now we will make a context API, so that everyone can get data. And we will also check. So here we make a file, a new file. We give it the name MyContext, mycontext.jsx. and here rafce not rafce actually createContext first createContext we will see later how to do production approach later. So, createContext is our hook. We'll call like this and give its name myContext. const myContext. Two stages I told you. Three stages basically. First of all, we had to create, provide and use. So, this is our create. Context has been created. Okay. Context has been created. Just this much? Yes, just this much. Context has been created. Let's export this. Export myContext. We are doing named export. You can also do default export for now. There is no issue. So we created context and exported it. Simple? Simple. Now, let's come to app.jsx. I want to get data from all components A, B, and AB in the app. So, I will wrap here. And if I want to use the data of the app component, which we are going to put in the context, then I will come to main.jsx and wrap the app in the provider. So, I do it here. I want everyone to get data. I will wrap the app. First of all, we will import mycontext. That's it. How simple was it? I did not do much. I made a context here, gave the name mycontext, exported it. The first work was very simple, create. While providing, I need to make sure that the components I put in the provider will work in all the child components. If I wanted, I could have put it in the app and wrapped the A and B components here. But we could not use that data in app.jsx. I want to use it in app.jsx as well. So what I did is I wrapped the app in myContext in main.jsx. But you don't have to wrap it in myContext. You have to use. provider here as well. If you want to provide data, you have to use. provider. Okay? So we used. provider and all the components in it are here. We basically put the app here, which means all of them are here. Now decide what data you want to provide. Let's say I want to provide value. For now, I just want to provide value. M-A-N-A-S K-U-M-A-R-L-A-L I want this data to be able to use all the components. Here an object can also be there, a state can also be added, anything can be added. But let's try a simple value first, then we will come to complex values. So here I have added a simple value, I want to be able to use it in the app too, I can use it in everything. So I wrapped the app, okay, I will come inside it, I can use it here, I can use it here too, I can use it in the A component too, I can use it in B too, D, E, F, whatever component I can use it in everything. Because I have wrapped the main component inside the provider. Okay. What is the value? This is the value. So, will everyone get this value? Yes, they will get it very easily. Do it and show. Okay. So, we have completed two stages. Which stages? Tell me quickly. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage of creating. We have completed the stage in app.jsx. So here, useContext. There is a hook, useContext. Simple. It has been imported. And we have also used it here. Okay. useContext. Now, in useContext, tell me which context to use. So, which context have you made? You have given the name of the context as myContext. Come here and see, what is the name of the context? MyContext. What have you exported here? MyContext. What are you providing? You are providing value from myContext. So, what will you use here? You will definitely use myContext. So remove this too. Here we have to use mycontext. So mycontext and import should also be done. Mycontext. Okay, no problem. We are not getting suggestions. We will import manually here. Although we will get suggestions. But we are not getting it now. I don't know why. Mycontext from. Mycontext. And here was named export. Default export was not there. So in this way, give mycontext. Okay. And we have to use mycontext here. Alright. So, we used context. Which context did you use? MyContext. We made MyContext. We used MyContext. Now, will we get data from this? Will we get the value we passed there? Exactly, we will get it. Const data is equal to... And I will tell you the proper approach. It will look a little complicated that make context there, provide here, use here. It will look a little complicated. I will tell you such approach which will make it very simple. But for now, there were three stages. Look at all three stages. So, will we get data here? Exactly, we will get it. I will give data here. I will also print it. Because it is a string, so it will be printed. So, look at this. Manas Kumar Lal. And this app is coming on the side. Okay. Let's do one thing. Let's wrap it with a paragraph. So that it becomes a block-level component. Okay. So, look at this. Manas Kumar Lal. We are able to use it in the app. Now, let's see if we are able to use it in the C component or not. Because there is A in the app and C inside A. So, let's see if we are able to use it in C. In app, it's A. And in A, it's C. We'll use it in C. If we had to do it first, then we'd have to drill a prop. First, we'd have to send the prop in A. Then, we'd have to send it in C. Now, we didn't send it in A. We'll access it in C. In the same way. What do we have to do? Use context. Which context? My context. Import is also done. Okay. And here, save it in a variable. const data is equal to and you can also see it by doing CLG. Or here, direct up. You can also print it. Because it is a string. So here we will use paragraph tag. And here we will print the data. So is this data available in C? Wow! It is available in app as well as in C. If I want, I can use it in app as well. See. You don't have to worry about which component is where. You know that you have wrapped the app. There are all the components in the app. So you can use it anywhere. Come to the app. You have to use it in the same way in the app. Use context. Which context? MyContext. Alright. And save it in a variable. You can give any name. I have given data. And you can either console it or print it. I will print it. Data. And I can see data here. Take this. So I am able to access data here too. In parent, in child and in its child too. I don't even need to send data in this. I sent the data to the main child which was needed. Here, I had a need for this, I sent it. I didn't even have a need to send it in B. It didn't happen that I sent it in app first, sent it in B, sent it in B, sent it in app. It didn't happen like that. I needed it in app, I gave it to direct app. Using use context. So, how much fun is this concept? That you make a global app, you tell who to provide to whom. While making global state, while making store, you tell who to provide to whom. So, I told here, coming to main.jsx, I told that to provide to app. Remove strict mode. He is confusing uselessly. There is no need of strict mode. Right? So, here, in this provider, I have wrapped the app. Wrapped the app, that means, it has been provided to everyone. Alright. What value have I passed? I have passed this value. Can I pass something else here? Definitely. Can I pass something else? Can I pass object? Can I pass state? simple value, simple value pass, I have shown, okay, state, pass, I will also do that, but now, let's go in a proper optimized way, this happened, that at one place, we basically created, while providing context, provided here, and then while using, now see carefully, if you observe carefully, then while using, we are importing use context, along with my context, we are importing, two things have to be imported, whenever we are using, two things have to be imported, use context also, and my context also, So, why don't we do this work here? Where? This whole work that we are doing, we do it in myContext. A little code will be optimized. Okay. So, let's do it here. Let's do it here. But now this data, okay, we will get the data. But how will it go out? So, to take it out, make a function. Const, give a name here. Use myContext. Use myContext. Okay. So, the use context is a hook. Use my context. I have given a name here. Use my context. So, you can say this is my own hook. Okay. We have made it our own. So, this is normally a function. What is it? It is a function. What are we doing in this? We are using use context. Use context. If you write it again, then use context will also be imported. And we have put my context in it. So, this provides your data. This is giving your data. You have made a provider. So, this is giving your data. So, you return it. Now, just send the use context here. Here, just send the use context. So, wherever you do use my context, this use context and my context, both of them, in combined way, as we used to use, and data will return to you. Okay. Yes, do it and see. See, I did use context here. And now, only this much is needed. Sorry, not use context. This is a hook, right? Use my context. Okay, you just need to do this much. And you remove this my context. And you had done it in the app as well. So, for now, remove this from the app as well. Okay. Here also, you have to do use my context in this way. Alright. Okay. Where else did we use it? See, otherwise you will get an error. Use my context was done in the app. Was it done in B? No. Was it done in C? Yes, it was done in C. So, here, use my context. That's all you have to do. You don't even need to import useContext and myContext. Now, wherever you want to use, you will have to import only one thing, which is useMyContext. And here you will get the data. Ok, let's see. Come here. Here also we are getting data. Here also we are getting data. Here also we are getting data. Wow, interesting. Now we have to import useContext twice, then import myContext, then useContext, then myContext, then we will get the data. No need to do that. We have done that here in myContext. We did it here and returned it. And made a function. So, you will get the data where you call this function. Wow! Now, there is one more thing. One thing is that in main.jsx, you are putting mycontext.provider and value here. Suppose the value is something long, we have to make a lot of states. So, everything will spread here, it will not look good. We have made context, so why don't we make that work in context too. But how will we do it here? The problem is how will we do it here? So we can do that work too. We know the strategy. In props, I told you that children. We can take children. What are we doing here too? If you look carefully in min.jsx, then in this context provider, children are passing. So as a props, receive these children and put them. How? You see here. You will understand all this in a very easy way if you have already followed the lectures. Rest, you can see what the syntax is like. So, const, here we give the name myContextProvider, myContextProvider, you can give any name, provider, okay? This will be your normal as a component treat, this will be your function treat, this will be your as a component treat. And what will we do here? Here, we will return, return, what to return? This whole thing. This here, Copy all of this from here. And paste it in the context. Here. Take this. You are getting myContext here. Dot provider. And we have passed the value here. Will we wrap the app in it? No. We will take children as a prop. We will pass the children that are coming here. Wow. We will pass the children that are coming here. Exactly. So, what will we have to do now? Come to main.jsx. Now, there is no need to do all this. This is useless. Remove all this. This is myContext. Remove all this. What you have to do here is, you have to pass the MyContext provider. There is no need for MyContext. You can use it from UseMyContext and provide it from the provider. The rest of the work is done here. See how simple it is. The same three parts are still going on. Here we have made the context. We are basically using it from UseMyContext. If you want, you can put it down. And here we are doing the work of providing. To provide, you give it. We have passed it here, exported it. You tell us where to provide it. So I have to provide this. So here I will bring my context provider here and here I will wrap it in app.jsx. That's it. Simple. Now we have only this much syntax left. We did this and wherever you have to use, just this much to use. Just. Will it be working? It should be. Look at this. Wow. We are able to receive data everywhere. It was fun. It should be fun too. Now let's see here. This one is understood, right? See this one once. Here we have created the context. Provide is done in the same way. Here we have changed the syntax a little. We are taking children. So wherever we have to use this context, we will wrap it there. And children will come here. So we wrapped it in the main component. So everyone will get this context. Okay. We wrapped the main app.js store. We passed it here. See. What are we passing here? We are passing an app. If we are passing an app, then it will be applied here. So, it will be applied to all the components, child, etc. in the app. And here, by using useMyContext, we are exporting, so we can use it by using useMyContext. So, you just have to export these two things. We are providing one and using one. And there are three steps, the same three steps. Okay. So, now, in this value, you can do something else and show it. So, I will show it. Look. The main purpose of React is to use state. We are changing one place and other places are reflected. For that, we have to make state. The method of making state is the same. Use state here. Because this is a component, so we can use state in component. So use state and here you basically give the count name, I give the set count name in this way. And now if you want to send both count and set count out, send both. If you want to provide count, just provide count. If you want to provide set count, just provide set count. If you want to provide set count, just provide set count. I want to provide everything. So what I will do here is, I will make cost value is equal to an object. And here I will send count, I will send set count. Do you know this syntax of object? If the key value pair is same here, like count, and here also it is count, Both are counts, so I can only write count here. This is a key and a value. Similarly, setCount is setCount. So, we will pass this whole object. Now, remove this and we will pass this whole object. So, we can access this count state everywhere. Along with this setCount function, it will be accessible everywhere. Really? Yes. Come here in A. So, now you won't be getting data, because it is an object, so the object cannot be printed here. So, remove this from everywhere. Remove it from here too. Ok, this is removed, this data is also not being received. All right. And what is the problem here? We removed some extra. Ok, this had to be removed, this had to be removed. Remove this whole thing, this is not being used. Remove this, the app component has been cleared. We had used it in B, we had used it in C. Remove this from C. And remove this whole thing here. Remove this whole thing. And we have also done it in app.jsx. So remove this. Remove this. And remove this use context etc. So now we have to use count and setCount. So I want to setCount in F and show it in C. I want to setCount in F and show it in C. Earlier this was not possible. Earlier we had to do a lot of prop drilling in app. We had to make state in main component and then pass it in sum. But we have made our state custom. We have made global state using context. and we are providing it to everyone. So, what you have to do here is simple. You have to do use in f. So, come here in f. How to use? Single function. Use myContext. Okay. So, will you get data from here? Yes. Again, you will get data. You can see the data by doing CLG. But this time, an object is coming in the data. Ctrl-Shift-I. Reload. And see here, an object is coming in the data. Count and setCount. The value of count is undefined for now. So let's come here in myContext and give the value of count as 0 in the starting. So now come here and see. So count is 0 and setCount is a function. So come here, remove B, remove A, remove main.jsx, remove f.jsx, come to F. So what we had to do in F, we just need setCount here. So no problem, by destructuring, because it is an object, so by destructuring, let's remove setCount from here. So we just need setCount here. So we took setCount and put a button here. button and here on click set count. Okay, in set count, count should also be there, then we will do count plus one. So for that, I have made a functional update for you, I have told you previous previous plus one. Here previous will be coming, state and we will do plus one in previous. So definitely if it is zero, then zero plus one, one will return and set count will happen. If you can't see this one, you can do this as well. You can do count and count plus one. So, now you can see all the basic things. So, we have done set count from here. So, will set count be happening? Definitely, it will be happening. Now, where do I want to show the increasing count? I want to show it in C. So, there is no dependency. You can show it anywhere. In A, B, C. Let's show it in C. So, here, use my context. And, Just call it and construct const here. What should we do? Construct count. We just need count here. So, we have constructed count. And here in h1 tag, we will show count. That's it. You want to show somewhere else. I want to show in b also. This component of b or the component of a, I want to show in a also. Okay. So, we will show here also. Take this. We will show here also. So, construct const. What was the name? Count. is equal to use my context and here is the count let's show here as well h1 at count you can show where you want to show and this error is giving for free actually there is no error here if you reload it will disappear reload ok and let's come here and see here the count value is 0 here also the count value is 0 and the button is set count ok there is nothing written in the button so let's write here in the button what should I write I will write COUNT. This is the COUNT button and we are able to use it here. If we click on COUNT here, then it will be 1 here. See this. You can keep multiple states like this. I have kept only one state here in myContext. I have kept only one state. Now you can make more states like this and pass them all to this value object. And whatever you find useful, remove it and work. So, this code has been arranged in an optimized way. You have made a single file. Your entire store is in this. Provider is also in this. You are just exporting two things here. MyContextProvider and UseMyContext. Okay. Again and again you have to import UseContext and then MyContext into it. That is not necessary. You will just call UseMyContext. You will get the data. MyContextProvider has and wrap it in the component, then all the things will be provided to you. Like we wrapped it here. That's it. And there are only three parts in it. Create, Provide and Use. Very simple. So, I hope you understood. It's not too complicated. If you follow those three parts, the rest of the state management video and the prop video you have seen, then you will find all this very simple. Because we have done more complicated things in previous lectures. This is quite simple. Okay. So, I hope you understood. which we worked on here, and whatever method we used, and if you get this code, I will push it, okay, if you don't need notes, because state management notes, I believe I gave it in the description, I will check it, I didn't give it, I will give it, and what will you do with it, okay, just keep this in mind, create context, provide context, use context, that's it, that's all there was in it, and then in the next lecture, maybe just end use, And you have to learn how to call API, how to put it in state, how to put it in global state, how to use it everywhere. So that's all in projects. Okay, that's all in projects. We have learned state management, now we will do the project. Alright. So, in the next lecture, maybe just end or maybe a project. Let's see what can happen. You comment, do you want a project? on context api then you will be able to practice more or you want to discuss just and so I think you should project a small one on context api and then after that just and and then after that if you do a project like this then it will be better rest you tell me by commenting ok so for now that's it till then explore a little more and if you get any interesting things in it then tell me and till then bye bye