liveBook · Manning

Component class

As explained in Build a Frontend Web Framework (From Scratch)

A class whose instances represent frontend components and can own state, render views, and manage their DOM lifecycle.

A component class defines the behavior shared by frontend component instances. Each instance can own state, render a virtual DOM view, and control when that view enters or leaves the browser DOM. section 9.2

A practical component class separates several responsibilities:

  • render() produces the virtual DOM for the specific component. section 9.2

Creating different component classes

defineComponent({ render }) acts as a factory: it creates a class whose render() method delegates to the supplied render function. CreateTodo and TodoList can therefore have different views, while each returned class can be instantiated repeatedly. Instance state can make otherwise similar instances render differently.

A component class can later become a parent as well as a view owner: subcomponents receive data through props, emit events upward, and clean up subscriptions during unmounting. section 11.0

How Build a Frontend Web Framework (From Scratch) covers it

How deep it goes
Defines rendering, mounting, unmounting, cleanup, and lifecycle validation, then extends the class toward props, events, and subcomponents.
Examples
Uses CreateTodo and TodoList classes plus mount and unmount calls to demonstrate rendering and invalid lifecycle operations.
What you can do after
Build component classes from render functions and operate their mount and unmount lifecycle safely.
How it connects
Connects virtual DOM, component lifecycle, state, factory functions, subcomponents, props, and events.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Frontend Web Framework (From Scratch). The section links point to the parts of the book it draws on.