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.
Avoiding the pitfall of prop drilling - React.js Tutorial
From the course: React: State Management (2019)
Avoiding the pitfall of prop drilling
- [Instructor] In almost every app I've worked in, I've seen a pattern like this. And if you're wondering what this is, this is actually just a pared down version of our book app that we've been working with. And to be clear I don't expect you to code anything with me this is just for your reference. So as you can see here props are passed down from component to component to component. Take a look at this update books fun. In the example here we're passing this updateBook function from the parent component to the child component to the grandparent component. But notice that the child component has no use for this prop at all. This is called prop drilling or threading in React and it's actually an anti-pattern. Your component should only have the data it needs to render and nothing more. Let's take a step back and see why prop drilling gets introduced in an application. In these sample components here we can actually render everything in one component like this. It avoids prop drilling…
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)
-
-
-
-