Type to search pages and rules.

Browse pages

React Components

Components in a React frontend are function components with typed boundaries.

Markdown2 rules

Intent#

Components in a React frontend are function components with typed boundaries. The shared provisions live on the stack-neutral page (Frontend components). This page states what React alone requires.

Standards#

Write components as functions#

ruleguidance

Requirement A component MUST be a function component using hooks, not a class component.

Rationale Hooks are the reactivity model the renderer understands. Class lifecycle methods fall out of every component. An effect covers what derivation cannot express.

Example

TSX
function OrderTotal({ orderId }: { orderId: string }) {
  const [quantity, setQuantity] = useState(1);
  const unitPrice = useUnitPrice(orderId);
  const total = quantity * unitPrice;
  return <Price value={total} />;
}
litespec/frontend/web/react/components#write-components-as-functions

Keep component boundaries typed#

rulecheckable

Requirement A component MUST type its props and its events under strict mode.

Rationale An untyped prop fails at the call site the next author writes, which is the most expensive place to learn a shape. Strict mode turns that failure into a build error.

litespec/frontend/web/react/components#keep-component-boundaries-typed

Conventions#

None.

Verification#

IDMarkEvidence
litespec/frontend/web/react/components#write-components-as-functionsguidanceIs every component a function component using hooks?
litespec/frontend/web/react/components#keep-component-boundaries-typedcheckablepnpm type-check runs under strict mode and fails on an untyped prop or event.