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.

Rendering & identity

Render a conditional branch

React

Use JavaScript expressions or branch before returning JSX.

Fragment

Before you use this

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

React · Render a conditional branch
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
{ready ? <Panel /> : <Spinner />}

Render a list with stable identity

React

Keys identify siblings across inserts/reorders. Use a stable item ID.

Fragment

Before you use this

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

React · Render a list with stable identity
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
{items.map(item => (
  <Row key={item.id} item={item} />
))}

Insert text without treating it as markup

React

JSX text expressions are escaped for the DOM.

Fragment

Before you use this

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

React · Insert text without treating it as markup
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
<p>{message}</p>