React components compose most clearly when each shared thing uses the right channel: pass markup through children or a named JSX prop, pass ordinary data through props, lift a coordinated state value to the closest common parent, use context when many or distant descendants need the same information, and extract custom Hooks to reuse stateful logic. These approaches solve different problems; none is a universal substitute for the others.
Use props and JSX to compose content
Props are the normal way for a parent component to communicate with a child. They can carry strings, objects, functions, and JSX—not just simple values. A component can therefore provide a wrapper while leaving the choice of inner content to its caller.
function Panel({ children }) {
return <section className="panel">{children}</section>;
}
function AccountPage() {
return (
<Panel>
<h2>Account</h2>
<p>Manage your profile settings.</p>
</Panel>
);
}
JSX nested between a component’s opening and closing tags is supplied to that component as its children prop. This creates a flexible content slot: Panel handles the surrounding structure without needing to know what its caller places inside. React documents this use of nested content in Passing Props to a Component and describes children as a React node supplied through JSX nesting in Common components (e.g. <div>).
When a component has several distinct content areas, a named prop can make the API clearer than multiple positional or nested conventions:
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
function Dialog({ title, actions, children }) {
return (
<section role="dialog">
<header>{title}</header>
<div>{children}</div>
<footer>{actions}</footer>
</section>
);
}
<Dialog
title={<h2>Delete item?</h2>}
actions={<button>Cancel</button>}
>
<p>This cannot be undone.</p>
</Dialog>
Use children when the content naturally belongs inside a wrapper. Use a named JSX prop when the component’s API has a specific slot—such as a title, icon, or action area—that benefits from an explicit name.
Keep data flow explicit with props
Props make dependencies visible: the parent supplies a value, and the child receives it for rendering or for a callback it can invoke. Treat props as read-only snapshots for a render. A child should not change a prop to update its parent; the parent owns the value and can pass a new one on a later render. React explains this model in Passing Props to a Component.
Passing props through a component that does not use them can become repetitive. Before adding broad prop spreads or forwarding several values through layers, check whether an intermediate component can instead receive the relevant JSX as children. That lets a layout arrange content without knowing every data dependency of the content it hosts. Explicit props remain useful when each intermediate component genuinely needs to inspect or transform the value.
Coordinate components by lifting state
If two or more components must stay in sync around one value, put that state in their closest common parent. The parent passes the current value down and supplies handlers through which children can request changes. This is called lifting state up; React’s guide Sharing State Between Components uses coordinated accordion panels to illustrate the approach.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchRank #3
function Accordion() {
const [activeIndex, setActiveIndex] = useState(0);
return (
<>
<Panel
isActive={activeIndex === 0}
onShow={() => setActiveIndex(0)}
/>
<Panel
isActive={activeIndex === 1}
onShow={() => setActiveIndex(1)}
/>
</>
);
}
function Panel({ isActive, onShow }) {
return isActive
? <p>Panel content</p>
: <button onClick={onShow}>Show</button>;
}
Here the parent owns the single active-panel value. Each child receives a derived Boolean and a callback; the child does not maintain a competing copy of the same state. A component is controlled when its important value is supplied and managed by its parent. It is uncontrolled when it manages that value internally. Choose based on who needs to coordinate the value, not on a blanket preference for one style.
Use context for information needed deeply or broadly
Prop drilling is the repeated passage of a value through components that do not themselves use it, simply so a deeper descendant can receive it. Context makes a value available to descendants without every intermediate component forwarding it. React’s Passing Data Deeply with Context discusses uses such as theming, the current account, routing, and state management.
Rank #4
Context trades explicit local dependencies for access across a descendant tree. Before introducing it, consider whether direct props are still clear, or whether component extraction can let an intermediate layout accept already-composed children. React specifically recommends considering these alternatives because context is easy to overuse. Prefer props when they make it obvious which component consumes a value; consider context when many or distant descendants genuinely need shared information.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Use custom Hooks to reuse behavior, not one shared state instance
A custom Hook packages reusable stateful logic behind a function whose name starts with use. For example, separate components can call the same online-status Hook to reuse how they subscribe to status changes. The Hook avoids duplicating that behavior, but each call has its own state. Calling a Hook in two components does not make those components share one state value. React makes this distinction in Reusing Logic with Custom Hooks.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Best Value
If components need one coordinated value, lift that state to a common owner and pass it down, or consider context when the value is broadly needed. A custom Hook can still help package the logic for that owner, but it is not itself a shared-state channel.
Keep composition correct during rendering
- Keep components and Hooks pure. Given the same inputs, rendering should produce the same result; do not perform side effects as part of render.
- Do not mutate props or state. Treat them as immutable and request updates through React’s state mechanisms.
- Let React invoke components. Render a component with JSX, such as
<Panel />, rather than callingPanel()as an ordinary function.
These rules preserve React’s ability to manage rendering consistently. See Rules of React.
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.




