What is a reusable component?
A reusable component is designed to work in many places with different data and behavior, by taking props instead of hard-coding content, keeping no assumptions about where it is used, and exposing a small, predictable API. Buttons, inputs, modals, cards and data tables are typical examples.
Traits of a good reusable component
- Configurable through props: content, variants (
size,variant), callbacks (onClose). - Composable: accepts
childrenor slots instead of a prop for every piece of text. - Extends native elements: forwards standard attributes (
...rest) such asaria-*,type,disabled, and acceptsref(a regular prop in React 19). - Accessible by default: correct roles, labels, keyboard handling and focus states.
- Controlled and uncontrolled support where it makes sense (
value/defaultValue,open/defaultOpen). - No business logic or data fetching inside; that belongs in feature components or hooks.
- Styled consistently through design tokens, Tailwind variants (
cva) or CSS Modules. - Typed and documented, for example in Storybook.
When not to generalize
Do not abstract until you have two or three real uses. Premature "do everything" components with dozens of boolean props are harder to use than duplication. Prefer composition.
Testing
Test behavior and accessibility (keyboard, roles), not implementation details.
Libraries
shadcn/ui, Radix UI, React Aria and Base UI provide accessible primitives you can style and wrap.
Code example
1type InputProps = React.ComponentProps<"input"> & {2 label: string;3 error?: string;4 hint?: string;5};67// Reusable, accessible input: forwards ref and native props (React 19: ref is a normal prop)8export function TextField({ label, error, hint, id, ref, ...rest }: InputProps) {9 const inputId = id ?? `field-${label.toLowerCase().replace(/\s+/g, "-")}`;10 const describedBy = [error && `${inputId}-error`, hint && `${inputId}-hint`].filter(Boolean).join(" ");1112 return (13 <div className="field">14 <label htmlFor={inputId}>{label}</label>15 <input id={inputId} ref={ref} aria-invalid={!!error} aria-describedby={describedBy || undefined} {...rest} />16 {hint && <small id={`${inputId}-hint`}>{hint}</small>}17 {error && <p id={`${inputId}-error`} role="alert">{error}</p>}18 </div>19 );20}2122// Usage in many places:23// <TextField label="Email" type="email" name="email" required hint="We never share it" />24// <TextField label="Coupon" error="Invalid code" maxLength={10} />
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.