PC 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 & 11Outdated 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 matchPass a value to a React component by putting it on the component’s JSX tag as a prop, then read it in the child from its props object. For example, <Avatar size={100} /> passes the number 100 as the size prop.
Pass a value with a JSX prop
A parent supplies props as attributes on a child component’s JSX tag. A function component receives those values together in one props object. You can use that object directly or destructure the properties in the function parameter; destructuring is shorthand for reading the same object.
function Profile() {
const person = { name: 'Lin Lanying', imageId: '1bX5QH6' };
return <Avatar person={person} size={100} />;
}
function Avatar({ person, size }) {
return <img alt={person.name} width={size} height={size} />;
}
In this example, person is an object and size is a number. The braces in JSX evaluate JavaScript expressions, so person={person} passes the variable’s value. To pass an object literal directly, use an outer pair of braces for the JavaScript expression and inner braces for the object: <Avatar person={{ name: 'Lin' }} />.
Props can hold strings, numbers, objects, arrays, and functions, as well as other JavaScript values. See React’s Passing Props to a Component guide for more examples.
#1 Best Overall
Choose defaults for optional props
If a component should use a value when a prop is omitted, set a default while destructuring:
function Avatar({ size = 100 }) {
return <img width={size} height={size} />;
}
This default is used when size is missing or undefined. It does not apply when the caller explicitly passes null or 0; those values remain null and 0.
Pass nested content with children
When a component wraps content chosen by its caller, put that content between the component’s opening and closing tags. React makes the nested JSX available to the wrapper as its children prop:
function Card({ children }) {
return <section className="card">{children}</section>;
}
function Profile() {
return (
<Card>
<Avatar size={100} />
</Card>
);
}
This pattern is useful for layout and wrapper components that should not need to know which specific content they contain.
Rank #3
Forward props when another component needs them
You can spread an existing props object onto a component to forward its properties:
function Profile({ avatarProps }) {
return <Avatar {...avatarProps} />;
}
Forwarding can reduce repetitive code, but it can also make the receiving component’s inputs less obvious. Prefer explicit attributes when they make the child’s interface clearer at the call site.
Rank #4
Let a child report interactions through a callback
Props can include functions. A parent can pass a callback so a child can report an interaction; the parent can then update its own state and render the child again with new prop values. The child calls the callback rather than changing a received prop.
function Parent() {
const [count, setCount] = useState(0);
return <Counter count={count} onIncrement={() => setCount(count + 1)} />;
}
function Counter({ count, onIncrement }) {
return <button onClick={onIncrement}>Count: {count}</button>;
}
Props are read-only snapshots: React’s documentation says, “Props are read-only snapshots in time: every render receives a new version of props.” The parent supplies changed values on a later render rather than the child mutating its props.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Best Value
Choose between explicit props, spreading, and Context
Use the approach that matches how widely the value is needed and how visible you want the component interface to be.
| Approach | Best fit | Trade-off |
|---|---|---|
| Explicit props | A small, local set of values for a particular child. | The call site clearly shows which values the child receives. |
| Spread forwarding | Passing an existing props object through to another component. | Can reduce repetitive forwarding, but may obscure the receiving component’s inputs. |
| Context | A value needed by many descendants, especially when passing it through intermediate components becomes inconvenient. | Avoids threading the value through each intermediate level, but is less direct than a local prop for one child. |
Start with ordinary props for parent-to-child data flow. Consider Context when the same information is needed broadly or across many tree levels.
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.




