React useContext Hook Explained in 2024

  Рет қаралды 199

BOOG Codes

BOOG Codes

3 ай бұрын

Want to master UseContext in just 90 seconds? Dive into this video to discover how the UseContext hook works with React's Context API to share values across components. Learn how to efficiently manage themes like dark and light throughout your entire application using context providers.
Subscribe now to level up your React skills in no time! / @boogcodes
Transcript:
You want to learn useContext in 90 seconds? HERE. WE. GO.
The useContext hook allows you to work with react's context API. This is a mechanism that allows you to share or scope values throughout the entire component tree.
Lets imagine we have an object called "theme" that can be dark or light. To share the current theme across multiple disconnecting components, we can create a context. One part of the application might be dark, so we use a context provider to scope the dark theme there.
Now, any child component inside of it can inherit that value without needing to pass down props to the children.
This brings us to the useContext hook. It allows us to access or consume the current value from the context provider. Which may reside many levels higher in the component tree. Reading a parent value from useContext is a whole lot easier than passing props down through multiple children.
Now, the theme changes from dark to light in the parent provider. The value here will be updated automatically. Now, if you've ever used react context in the past, you've likely used the consumer component. The useContext hook is pretty much just an easier replacement for the consumer.
useState() is the most important hook to learn for React. useState is the most commonly used hook as well, and you can learn it in 90 seconds by watching my useState video next!

Пікірлер: 4
@BoogCodes
@BoogCodes 3 ай бұрын
This is my third video in the React Hooks in 90 seconds series! Watch the playlist to learn useState & useEffect - kzbin.info/aero/PLew986vU76wjN8T2w0asO8ZWZrRQiGaJq useMemo next!
@DavidG-oj1yx
@DavidG-oj1yx 3 ай бұрын
nice recap of use context. I used react context in my previous project
@BoogCodes
@BoogCodes 3 ай бұрын
The useContext hook is very useFul!
@JocyJoey
@JocyJoey 3 ай бұрын
nice
React Hooks: Learn useMemo & useCallback in 90 seconds!
1:22
Learn React Hooks: useRef - Simply Explained!
12:42
Cosden Solutions
Рет қаралды 76 М.
Sprinting with More and More Money
00:29
MrBeast
Рет қаралды 136 МЛН
The Worlds Most Powerfull Batteries !
00:48
Woody & Kleiny
Рет қаралды 25 МЛН
Did you find it?! 🤔✨✍️ #funnyart
00:11
Artistomg
Рет қаралды 126 МЛН
Understanding Identifiers in C++ : A Step-by-Step Tutorial
6:32
Luqman Tutorials
Рет қаралды 9
Every React Concept Explained in 2024
4:31
BOOG Codes
Рет қаралды 3,8 М.
4 Ways you can Level up as a Developer
9:08
Ben Awad
Рет қаралды 18 М.
Learn React Hooks: useMemo - Simply Explained!
13:41
Cosden Solutions
Рет қаралды 76 М.
Sprinting with More and More Money
00:29
MrBeast
Рет қаралды 136 МЛН