Course contentsShow
← React
Lesson 238 of 2,3967. Props FundamentalsFree lesson

Multiple Callbacks for Different Actions

Passing several callback props to handle different user interactions like onEdit, onDelete, onSelect.

Multiple Callbacks for Different Actions

What you'll learn: How to pass several callback props to a single component so it can trigger different parent actions.

The Core Idea

Sometimes a component needs to do more than one thing. A <UserCard> might need to let the parent know when the user clicks "Edit," "Delete," or "Select." Instead of passing one callback prop, you pass multiple callbacks—one for each action.

Each callback prop has a descriptive name that explains what it does:

function UserCard({ user, onEdit, onDelete, onSelect }) {
  return (
    <div>
      <h3>{user.name}</h3>
      <button onClick={() => onEdit(user.id)}>Edit</button>
      <button onClick={() => onDelete(user.id)}>Delete</button>
      <button onClick={() => onSelect(user.id)}>Select</button>
    </div>
  );
}

The parent component defines what each action actually does:

function App() {
  const handleEdit = (id) => {
    console.log('Editing user:', id);
  };

  const handleDelete = (id) => {
    console.log('Deleting user:', id);
  };

  const handleSelect = (id) => {
    console.log('Selecting user:', id);
  };

  return (
    <UserCard
      user={{ id: 1, name: 'Alice' }}
      onEdit={handleEdit}
      onDelete={handleDelete}
      onSelect={handleSelect}
    />
  );
}

Why Use Multiple Callbacks?

This pattern keeps your component flexible and reusable. The <UserCard> doesn't care what happens when you click "Delete"—it just knows to call onDelete. The parent decides the behavior. Different parents can pass different callbacks for the same component.

Key Takeaway: Pass multiple callback props (like onEdit, onDelete, onSelect) to handle different user interactions, keeping your components flexible and letting parents control the behavior.