Declare a component
#A function returns JSX. Component names begin with a capital letter.
Fragment
Before you use this
React TypeScript/JSX project; use body fragments in a component and supply app-owned names.
Reference
Compare native component, state, event and lifecycle syntax in four frameworks.
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.
React docs Your first component ↗Passing props ↗
A function returns JSX. Component names begin with a capital letter.
Fragment
Before you use this
React TypeScript/JSX project; use body fragments in a component and supply app-owned names.
Props are inputs owned by the caller; do not mutate them.
Fragment
Before you use this
React TypeScript/JSX project; use body fragments in a component and supply app-owned names.
A destructuring default applies when the prop is undefined.
Fragment
Before you use this
React TypeScript/JSX project; use body fragments in a component and supply app-owned names.
Call ordinary Hooks at the top level of a component/custom Hook before conditional returns. A condition can select rendered output after the Hooks have run.
Fragment
Before you use this
React TypeScript/JSX project; use body fragments in a component and supply app-owned names.
import { useState } from "react";The use API has distinct documented rules; do not generalize its exceptions to useState/useEffect.