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?

Who owns state?

From the course: Web Components and Modularization: Practical Approaches

Start my 1-month free trial

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…

Contents