Quick answer
Use a small props object for one component mode and a discriminated union when modes require different fields. Extend native element props when the component genuinely preserves that element’s behavior. Make controlled and uncontrolled state contracts explicit. TypeScript should reject contradictory combinations at the call site; runtime validation remains necessary for API, CMS, or URL data that did not originate in typed application code.
Practical implementation steps
1. Separate semantic modes
A navigation control requires a destination; an action control requires behavior. One object with optional href and optional onClick accepts neither, both, and other combinations that reviewers must reason about manually. A kind discriminator makes each mode explicit and lets TypeScript narrow its required fields. Render an anchor for navigation and a button for an action rather than using types to conceal incorrect HTML semantics.
2. Preserve native behavior intentionally
ComponentPropsWithoutRef<"button"> can inherit familiar disabled, type, accessibility, and event props. Omit or redefine a field only when the component owns its meaning. In React 19, refs can be passed as props to function components; older forwardRef advice should be interpreted against the supported React version. Do not expose every native field if a specialized component cannot safely honor it.
3. Decide who owns state
A controlled field receives value and a change callback; an uncontrolled field can receive defaultValue. Avoid accepting both without a documented precedence rule. Children should also have a deliberate contract: ReactNode allows normal rendered content, while a render-function prop is a separate API. Prefer a concrete domain component to a fully polymorphic generic until several real callers need that flexibility.
Implementation example
This union prevents a link from receiving action-only props and requires an action callback. The never fields improve feedback for object literals. Event handlers require a Client Component boundary in an App Router application, so this module declares that boundary. The example performs no server mutation and does not imply that a typed callback is authorized.
"use client";
import type { ReactNode } from "react";
type ControlProps = { children: ReactNode } & (
| { kind: "link"; href: string; onPress?: never }
| { kind: "action"; onPress: () => void; href?: never }
);
export function Control(props: ControlProps) {
if (props.kind === "link") {
return <a href={props.href}>{props.children}</a>;
}
return (
<button type="button" onClick={props.onPress}>
{props.children}
</button>
);
}
Tradeoffs and alternatives
Simple interfaces are easier to read than elaborate generics when the component has one behavior. Unions make incompatible modes visible but can become cumbersome if they encode too many unrelated features. Split components when their interaction and semantics differ substantially. Shared visual styling does not require one shared runtime API; a Link and an ActionButton can use the same styles with clearer contracts.
Common mistakes
Avoid any, unchecked casts, and a broad string index signature that makes arbitrary props appear valid. Do not destructure away a discriminator before narrowing when that loses the relevant relationship. Do not spread unknown CMS fields onto DOM elements. Finally, required TypeScript fields are not runtime input validation: JSON can still omit them or carry a different type after the application is deployed.
Production checklist
- Each component mode has the fields it actually requires.
- Invalid mode combinations fail at typed call sites.
- Native semantics and accessibility props remain usable.
- Controlled state has a clear owner.
- External data validates before becoming props.
FAQ
Should every component use React.FC?
No. A function with an explicit props parameter is sufficient. Choose a consistent local style; the important work is modeling props correctly rather than adding a particular annotation.
Can a union replace runtime validation?
No. It constrains checked TypeScript callers. Parse unknown external values at the boundary, then return a validated domain value that the component can consume.
Next step
Find one component accepting contradictory optional props. Replace those combinations with explicit semantic modes, verify real callers, and keep the rendered HTML behavior intact. Extract shared styling before introducing generic polymorphism that the current product does not need.
Primary sources
Related guides and examples
Need this implemented in a real product?
React and Next.js applications with deliberate rendering, reliable data flows, and a clear path to production.