liveBook · Manning

Presentation component

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

A user-interface component whose output is determined by inputs and which does not maintain its own mutable state.

A presentation component describes what a view should look like without directly performing DOM updates. Its output comes from inputs, while application state remains outside the component. This separates application logic from low-level DOM manipulation and keeps the view easier to maintain. section 3.0 section 1.2.2

A simple presentation component has three responsibilities:

  • Receive application data as inputs. section 1.2.2
  • Return a virtual DOM representation of its view. section 1.2.2
  • Leave DOM reconciliation and the entire application state to the surrounding application or framework. section 1.2.2

A small view function

function greetingView(name) { return { type: "h1", children: ["Hello, " + name] }; } The function receives its input and returns a description of the view. It does not store application state or manipulate the DOM directly; a framework can reconcile the returned representation with the document. section 1.2.2 section 3.0

Figure 1.3 Implementation plan for the framework we’ll build
figure

Use the implementation plan to place stateless components before stateful components, subcomponents, and lifecycle hooks. section 1.2.2

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

How deep it goes
Defines stateless components as pure functions returning virtual DOM, while deferring reconciliation and component-owned state.
Examples
Uses a vanilla JavaScript application, pure view functions, and an implementation plan for progressively building framework features.
What it assumes
Assumes familiarity with application logic and DOM manipulation, while using vanilla JavaScript to establish the framework concepts.
What you can do after
Build it from scratch by extracting view logic into pure functions that return virtual DOM representations.
How it connects
Connects virtual DOM, global application state, DOM reconciliation, and stateful components.

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.