Child-to-Parent Communication
โš›๏ธ React 18+ ๐ŸŸข Chapter 17 of 39 ๐Ÿ“‚ Phase 07: Component Communication ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Callback Props ยท Sending Data to Parent ยท Child Event Handling ยท Updating Parent State ยท Reusable Modal
Since data only flows downward through props, how does a child tell its parent that something happened โ€” a button was clicked, a form was filled in? The answer is callback functions, passed down as props and called back up.
1The Callback Prop Pattern
๐Ÿ’ป Example 1: Child Notifying Its Parent
function Child({ onSelect }) {
  return (
    <button onClick={() => onSelect("React")}>
      Select React
    </button>
  );
}

function Parent() {
  function handleSelect(value) {
    console.log(value);
  }

  return <Child onSelect={handleSelect} />;
}
๐Ÿ” How This Works:

The parent defines handleSelect and passes it down as the onSelect prop. The child doesn't know or care what the function does โ€” it just calls it, passing back whatever data is relevant (here, the string "React").

2Updating Parent State from a Child
function SearchBox({ onSearch }) {
  const [query, setQuery] = useState("");

  function handleSubmit(e) {
    e.preventDefault();
    onSearch(query);
  }

  return (
    <form onSubmit={handleSubmit}>
      <input value={query} onChange={(e) => setQuery(e.target.value)} />
    </form>
  );
}

function App() {
  const [results, setResults] = useState([]);

  function handleSearch(query) {
    setResults([`Result for ${query}`]);
  }

  return <SearchBox onSearch={handleSearch} />;
}

Note that the query input's own text is local state owned by SearchBox itself โ€” only the final submitted value gets communicated up to the parent, a very common and clean division of responsibility.

3A Reusable Modal Using Callback Props
function Modal({ isOpen, onClose, children }) {
  if (!isOpen) return null;

  return (
    <div className="modal-overlay">
      <div className="modal-content">
        {children}
        <button onClick={onClose}>Close</button>
      </div>
    </div>
  );
}

A reusable Modal doesn't know anything about why it should close โ€” it just calls whatever onClose function its parent gave it, letting the parent fully control whether the modal is open via its own state.

โš ๏ธ Naming Callback Props Unclearly

Naming a callback prop something vague like onClick when it actually represents a higher-level action (like submitting a search or selecting an item) makes components harder to understand at a glance. The React convention is to name callback props starting with on followed by a clear description of the event: onSearch, onSelect, onDelete.

๐Ÿ’ป Hands-on Interactive Practice Challenge

Build a parent component that shows a count, and a child Counter component with + and - buttons that call callback props to update the parent's state.

React Practice Challenge โ–ถ Run in Compiler
function Counter({ onIncrement, onDecrement }) {
  return (
    <div>
      <button onClick={onDecrement}>-</button>
      <button onClick={onIncrement}>+</button>
    </div>
  );
}

function App() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <Counter
        onIncrement={() => setCount(c => c + 1)}
        onDecrement={() => setCount(c => c - 1)}
      />
    </div>
  );
}
Run This Challenge in Online JS IDE โ†’
โ“ Frequently Asked Questions (FAQ)

Q Is 'callback prop' a special React feature?

No โ€” it's just a regular JavaScript function passed as a prop, following a naming convention (onSomething). React doesn't do anything special with it beyond passing it down like any other prop value.

Q Can a child component call a callback prop with multiple arguments?

Yes โ€” a callback prop is just a normal function, so it can be called with as many arguments as the parent's function definition expects, e.g. onUpdate(id, newValue).

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on React 18+ ยท Last updated August 2026