From the course: Web Components and Modularization: Practical Approaches
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Who owns state?
From the course: Web Components and Modularization: Practical Approaches
Who owns state?
- [Instructor] When working with state, it's important to carefully consider where that state belongs. At what level or layer is it controlled? In most basic implementations, state belongs to the component itself. Activate a button, the button state changes to reflect a click occurred. However, in many cases you'll find an interaction with one component should change the state of another component. In those circumstances, which happen more often than you'd think, you need a method for figuring out where that state belongs. The basic rule of thumb here is, state belongs to the closest common ancestor, whatever that ancestor may be. And that means, state will often appear in a place that doesn't seem logical at first. Let's say we have a shopping cart view with two components, the product list on the left and the summary CTA with taxes, shipping, total price, and a place your order button on the right. These two…
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)
Plan before you code1m 25s
-
(Locked)
Raw output2m 32s
-
(Locked)
Properties1m 49s
-
(Locked)
Input and output3m 27s
-
(Locked)
State2m 7s
-
(Locked)
Who owns state?2m 11s
-
(Locked)
Life cycle1m 18s
-
(Locked)
Challenge: Scope a complex component1m 20s
-
(Locked)
Solution: Scope a complex component5m 5s
-
(Locked)
-
-