From the course: React: State Management (2019)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Defining Context - React.js Tutorial
From the course: React: State Management (2019)
Defining Context
- [Instructor] React's context API is a great way to manage state without introducing a third-party library like Mobx or Redux. Before context, React developers didn't have an easy way to manage state in mid-sized applications. The options were to either use prop drilling, which introduces unnecessary confusion or bring in Redux, which introduces unnecessary complexity. Context exists for small to mid-sized applications that need some way to know about data without prop drilling. If you're wondering what the threshold is where prop drilling becomes a problem, my personal heuristic is asking myself if I'm annoyed passing down props from component to component, which typically happens if I'm prop drilling through three components. So let's take a look and see what exactly is context? It's a way to broadcast data to other components. React uses the terms providers and consumers for the two types of components involved in context. There's a component which provides state and components…
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.
Contents
-
-
-
(Locked)
Avoid prematurely adding state management packages3m 2s
-
(Locked)
The power of setState()3m 21s
-
(Locked)
Data fetching only using React4m 16s
-
(Locked)
Avoiding the pitfall of prop drilling4m 2s
-
(Locked)
Defining Context2m 2s
-
(Locked)
Using the Context API4m 30s
-
(Locked)
Implementing Hooks3m 23s
-
(Locked)
React Hooks: Refactoring2m 32s
-
(Locked)
-
-
-
-