From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Challenge: Manage a global state
From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Challenge: Manage a global state
- [Instructor] Let's complete the app by refactoring by using the hook useContext. The goal with this exercise is to learn to manage the state with one single source of truth. So we're going to do that by using another hook, which is useContext. That allows to share global state with components without doing any props drilling. So the way this works is that this useContext accepts one parameter, which is the context object, to return the current state value. Let me show you how. So what we've been doing so far is to use this setup with the component provider to pass data down to child components, by using this single prop, which is the value. So basically, what's going to help doing this useContext, is to take as a parameter this context object, to then return the global value, which is set up right here. So let me show you one quick example. We're going to go to the app components and I'm going to add to the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.