13 The component lifecycle hooks and the scheduler

This chapter covers

  • Understanding a lifecycle hook
  • Executing code when a component is mounted
  • Executing code when a component is unmounted
  • Publishing version 4 of the framework

It’s not uncommon for a component to execute some code when it’s mounted into or unmounted from the Document Object Model (DOM). The classic example is fetching data from a server right after the component is mounted. In that case, the component is already part of the DOM, so it can display a loading indicator while the data is being fetched. When the data is ready, the component updates its view by removing the loading indicator and rendering the newly fetched data.

Your existing framework runs code only when ...

Get Build a Frontend Web Framework (From Scratch) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.