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.

Composition & sharing

Accept caller-supplied content

React

children or named ReactNode props accept composed UI.

Fragment

Before you use this

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

import type { ReactNode } from "react";
React · Accept caller-supplied content
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
function Card({ children }: { children: ReactNode }) {
  return <section>{children}</section>;
}

Provide a value to descendants

React

Context shares a value with descendants. The nearest matching provider wins.

Fragment

Before you use this

React TypeScript/JSX project; use body fragments in a component and supply app-owned names. Provider shorthand: React 19+.

import { createContext, useContext } from "react";
React · Provide a value to descendants
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const ThemeContext = createContext("light");
// Provider (React 19+):
<ThemeContext value="dark"><App /></ThemeContext>
// Descendant:
const theme = useContext(ThemeContext);

Reach an imperative platform object

React

A ref retains a DOM handle without making ref writes reactive.

Fragment

Before you use this

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

import { useRef } from "react";
React · Reach an imperative platform object
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const input = useRef<HTMLInputElement>(null);
<input ref={input} />
// In an event handler:
input.current?.focus();