Pass data to a React component as props: <Greeting name="Ada" /> gives the component a name prop. To pass an argument to an event handler later, pass a function that supplies it: onClick={() => handleSelect(item.id)}. These are related but different tasks—one supplies component input; the other schedules a function call for an event.
Pass data to a component with props
JSX attributes on a custom component become fields on its props object. A function component receives that one object; you can access it directly or destructure the fields you need. React describes the role simply: “React components use props to communicate with each other.” See React’s guide to passing props.
function Greeting({ name }) {
return <h1>Hello, {name}</h1>;
}
function App() {
return <Greeting name="Ada" />;
}
Here, Greeting receives a props object whose name field is "Ada". The destructured form function Greeting({ name }) binds that field. By contrast, function Greeting(name) binds the entire props object to the variable name; it does not extract the name field.
Pass JavaScript values, not only strings
Use curly braces in JSX to pass a JavaScript expression, such as a number, object, array, or function. Quoted attributes are convenient for string values.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
function Avatar({ person, size = 100 }) {
return (
<img
src={person.imageUrl}
width={size}
height={size}
alt={person.name}
/>
);
}
function Profile() {
const person = { name: "Ada", imageUrl: "/ada.png" };
return <Avatar person={person} size={80} />;
}
The size = 100 default applies when size is omitted or undefined. It does not replace null or 0.
Pass an argument to an event handler
If a click should call a function with a particular value, pass an arrow function as the handler. The arrow function runs when the event occurs, and calls your function with that value. React’s event guide emphasizes: “Event handlers must be passed, not called!” See Responding to Events.
function Toolbar({ item }) {
function handleSelect(id) {
console.log("Selected", id);
}
return (
<button onClick={() => handleSelect(item.id)}>
Choose
</button>
);
}
For a handler that needs no extra argument, pass the function itself: onClick={handleClick}. Avoid onClick={handleClick()} when you mean to handle a later click: that expression invokes the function during rendering and passes its return value instead of a handler. The arrow wrapper defers the call and binds item.id for that event.
Forward a handler through a custom component
A parent can pass a function as a prop, and a child can attach it to a built-in element. The custom prop name is up to the component; the DOM button uses onClick.
Rank #3
function Button({ onClick, children }) {
return <button onClick={onClick}>{children}</button>;
}
function Toolbar({ item }) {
function handleSelect(id) {
console.log("Selected", id);
}
return (
<Button onClick={() => handleSelect(item.id)}>
Select
</Button>
);
}
When a handler needs the browser event as well, React supplies the event to the handler. Define the handler to accept it where needed, and deliberately decide how any additional value is supplied. The React reference for common DOM components documents built-in event props.
Choose a clear prop shape
| Approach | Example | Good fit |
|---|---|---|
| Separate named props | <Avatar person={person} size={80} /> |
Inputs should be explicit and easy to see at the call site. |
| Grouped object | <Avatar person={person} /> |
Related values already belong together as one object. |
Nested JSX as children |
<Card><Avatar person={person} /></Card> |
A wrapper should display supplied content without needing to inspect its details. |
Nested JSX is received through the children prop:
function Card({ children }) {
return <section className="card">{children}</section>;
}
When passing values onward, you can list them explicitly so the receiving component’s inputs remain visible:
Rank #4
function Profile({ person, size }) {
return <Avatar person={person} size={size} />;
}
JSX spread can forward a set of props, as in <Avatar {...props} />. Use it selectively: if components repeatedly forward props they do not use, composing them with children may make the relationship clearer. These prop-shape choices and examples are covered in React’s props guide.
Keep props read-only
Treat props as inputs to a render, not as data for a child to modify. If an interaction should change displayed data, have the child call a function supplied by the parent; the parent updates its own data and renders the child again with new props. This keeps ownership of the value with the component that can update it.
Best Value
Know the client/server boundary
The examples here describe ordinary client-side component composition. In a server-component setup, event handlers cannot be passed as props across a client/server boundary; the exact boundary rules depend on the framework and component context. React’s error reference for error 374 flags this limitation, so do not assume a callback prop can cross every such boundary.
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.




