From the course: React: State Management
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Create a context object and a provider - React.js Tutorial
From the course: React: State Management
Create a context object and a provider
- [Instructor] Let's begin with the context API. First, we want to create a new context object. So we do that with this method, which is createContext. And so, every new context object comes with one component provider that we use to share global states across the application. So let's say one quick example, createContext that we're going to use to create a new context objects. And in this example, we want to share common settings about this style in order to change the appearance across the entire application. And so, every context object comes with one component, the provider, that will allow to share global states across the application. And what we're going to do with this component provider is to wrap the top level component, so any components, descending components of this component provider will have access to the global state. And so, this component provider accepts one single prop value that we're going to use to…
Contents
-
-
-
-
-
(Locked)
Why is a single source of truth important?2m 26s
-
(Locked)
Getting started with the context API1m 18s
-
(Locked)
Create a context object and a provider3m 41s
-
(Locked)
Create and manage a global state2m 1s
-
(Locked)
Challenge: Scaling and maintaining apps3m 3s
-
(Locked)
Solution: Subscribing to the context changes6m 59s
-
(Locked)
-
-
-