Complete worked example
typescript
import type { ReactNode } from "react";
type Props = { saved: boolean; onToggle: (next: boolean) => void; children?: ReactNode };
export function SaveButton({saved,onToggle,children}: Props) {
return <button type="button" aria-pressed={saved} onClick={()=>onToggle(!saved)}>{children ?? "Save role"}</button>;
}- Reasoning
- Props connect the displayed state to a boolean callback; the parent remains the state owner.