Clean React code comes from giving components clear responsibilities and composing them around the ways their callers actually need to vary—not from making every component tiny or adding a flag for every exception. Use children for caller-supplied content inside a wrapper, named element props for distinct content regions, ordinary props for values and actions, lifted state for coordinated siblings, and context when information must reach many descendants.
What component composition means in React
React components are reusable, nestable pieces of UI that can be arranged into a page. A parent can pass a child JavaScript value, callback, object, array, or JSX element through props; the child then renders or uses that input. The relationship stays visible: callers decide what to pass, and components decide how to present it. See React’s Describing the UI and Passing Props to a Component.
As an Amazon Associate I earn from qualifying purchases.
Composition is most useful when a component has a stable job but its content needs to vary. Instead of making a single component understand every consumer’s title, body, footer, and special case, separate the stable frame from the content each caller supplies.
Replace special-case flags with caller-controlled content
Imagine a rigid Card API that takes title, body, and footer, plus booleans such as showAvatar or compact added for particular screens. As the cases accumulate, the component has to know about more layouts than its basic job requires. For a card whose contents are chosen by its caller, put the shared frame in one component and the content in another:
#1 Best Overall
function Card({ children }) {
return <section className="card">{children}</section>;
}
function ProfileCard({ person }) {
return (
<Card>
<h2>{person.name}</h2>
<p>{person.bio}</p>
</Card>
);
}
Here, Card owns the common section, while ProfileCard owns the profile-specific content. The wrapper does not have to predict the markup that will appear inside it. This is the usual fit for children: one content area, supplied by the caller. React explains this pattern in Passing JSX as children.
When to use children versus named element props
Use children when the component is a wrapper around content. If the layout has several distinct regions, name them so the component’s API makes those slots clear:
function SplitPane({ left, right }) {
return (
<div className="split-pane">
<aside>{left}</aside>
<main>{right}</main>
</div>
);
}
A caller can pass JSX into both left and right. The names explain where each element belongs; they are not special React syntax. React’s archived guide uses this named-prop pattern in its Composition vs. Inheritance example.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →| Need | Prefer | Reason |
|---|---|---|
| One area of content chosen by the caller | children |
The wrapper can render content without knowing its details in advance. |
| Several distinct areas, such as left and right | Named element props | The API identifies each content region. |
| A child needs a value or action from its parent | Ordinary props | Props communicate parent-to-child inputs explicitly. |
Do not add flexibility simply because a component could support more options. A useful API exposes the variation its callers need while keeping the component’s purpose understandable.
Rank #3
Use props for direct communication
Props are the straightforward choice when a child needs a value or callback from its parent. Pass the relationship directly rather than hiding it in a broad configuration mechanism. For example, a parent can pass a selected value and an event handler to a child that displays and updates it. React’s props guide covers values, functions, and JSX as component inputs.
Coordinate sibling components by lifting state
When two or more components need to stay in sync, put the shared state in their closest common parent. That parent can pass the relevant value and event callback to each child, giving the group one source of truth. In React’s Accordion example, the parent tracks the active panel and passes each panel an isActive value and an onShow callback. See Sharing State Between Components.
Rank #4
- Identify the components that must coordinate and find their closest common parent.
- Move the shared state to that parent.
- Pass each child the value it needs and callbacks for actions that should update the state.
This keeps state ownership near the components that coordinate, instead of duplicating state and trying to keep copies aligned.
How to avoid prop drilling without overusing context
Context is useful when many descendants need the same information or when passing it through layers of components that do not use it becomes inconvenient. It lets a component provide information for descendants to read without explicitly threading that value through every intermediate component. React describes this use in Passing Data Deeply with Context.
Best Value
Context is not a replacement for every prop. For ordinary parent-to-child communication, props keep the data flow explicit. Consider context when the value is genuinely shared across a deep or broad part of the tree; otherwise, passing a prop directly is usually easier to follow.
Prefer composition to inheritance for UI reuse
React’s longstanding documented guidance favors composition over inheritance for reusing components. Its composition guide is archived and marked as no longer updated, so treat it as historical guidance alongside the current documentation on passing props and passing JSX as children. Reuse non-UI logic in ordinary JavaScript functions or modules rather than extending a component just to share that logic.
Keep component definitions stable and rendering pure
Define components at the top level
Do not declare a component function inside another component’s function. A nested declaration creates a new component identity during rendering, which React warns can be slow and cause bugs. Define component functions at the module’s top level and pass changing data through props. See Your First Component.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Keep side effects out of render
Rendering should be pure: the same inputs should produce the same result, and rendering should not mutate values outside the component. React may render more than once, so put side effects in event handlers or effects rather than performing them during render. The React purity rules describe these expectations. The referenced purity page displayed React v18.3.1; the current Learn pages displayed v19.3 when checked on October 7, 2026.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




