Reference

UI framework equivalents

Compare native component, state, event and lifecycle syntax in four frameworks.

Scope and conventions

React function components, Svelte 5 runes, modern SwiftUI (Observation examples require iOS 17+) and Jetpack Compose. Snippets are independent component/body fragments; import the named framework APIs. Native lifecycle and ownership rules differ.

Layout & accessibility

Arrange a vertical group with spacing

React

Web layout uses CSS independently of the component model.

Fragment

Before you use this

React TypeScript/JSX project; use body fragments in a component and supply app-owned names.

React · Arrange a vertical group with spacing
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
  <Title /><Content />
</div>

Give an icon action an accessible name

React

Prefer a semantic button; supply a name when the content is only an icon.

Fragment

Before you use this

React TypeScript/JSX project; use body fragments in a component and supply app-owned names.

React · Give an icon action an accessible name
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
<button aria-label="Close" onClick={close}>
  <CloseIcon aria-hidden="true" />
</button>

Reflect state in styling and disabled actions

React

Use state to choose classes and native control properties. disabled changes interaction; CSS color alone does not disable a button.

Fragment

Before you use this

React TypeScript/JSX project; use body fragments in a component and supply app-owned names.

React · Reflect state in styling and disabled actions
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
<button
  className={active ? "active" : "idle"}
  disabled={!canSave}
  onClick={save}
>Save</button>