From the course: React: Software Architecture
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Accessing context inside components
From the course: React: Software Architecture
Accessing context inside components
- [Instructor] So at this point, we're providing the context to any component inside of this provider that wants it. So what we're going to do is open up our CounterButton component now and allow it to access the value of that context. So here's what that's going to look like. We're going to start off by saying import useContext from react, and we're going to import our CounterContext. We'll say import CounterContext from CounterContext. All right, and now we're going to use this useContext hook in conjunction with our CounterContext to get the current value of this useState hook inside our CounterProvider. So here's what that'll look like. We're going to say const, and we're going to use object destructing here to get both the numberOfClicks and the increment function. And we'll say equals useContext and pass the CounterContext as an argument. Okay, now we'll get to this incrementBy thing in a second. Let's just comment…
Contents
-
-
-
-
-
(Locked)
What is state management?3m 25s
-
(Locked)
Small state with the useState Hook5m 20s
-
(Locked)
Small state with context5m 48s
-
(Locked)
Accessing context inside components4m 53s
-
(Locked)
Medium state with Recoil6m 7s
-
(Locked)
Sharing Recoil state6m 49s
-
(Locked)
Using Recoil selectors5m 9s
-
(Locked)
Big state with Redux6m 29s
-
(Locked)
Using Redux with components8m 1s
-
(Locked)
Big state with MobX7m 48s
-
(Locked)
-
-
-
-