From the course: React: State Management
Unlock the full course today
Join today to access over 25,200 courses taught by industry experts.
Getting started with the context API - React.js Tutorial
From the course: React: State Management
Getting started with the context API
- [Instructor] In a typical React application, data is passed top-down, from parents to child, via the props. This needs to be done manually, from top to bottom, by going through every component's level, which can be very tedious and difficult to maintain. This works very well for small and basic applications. But imagine you have much bigger applications with multiple levels. It can become very challenging. And so the more complex is the application, the more complex is the communications between components and the more complex it is to share the state across the application. The solution is the Context API. That is a way to share values without having to explicitly and manually pass the data from the parents to the child components. So why use a context object and the Context API? First, it provides a way to manage the application state in a single, centralized location. And it helps to avoid the common pitfall of props…
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)
-
-
-