DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

React Parent-to-Child Function Calls: The Callback Pattern and When to Use a Ref

In React, a child triggers parent-owned work by calling a callback function passed down as a prop. Use refs only for imperative child operations such as focus or scroll.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If a child component needs to trigger work owned by its parent, define the function in the parent and pass it to the child as a callback prop. The child calls that callback in response to an event; it does not need to reach upward into the parent.

function Parent() {
  function handleAction() {
    console.log('Action requested by child');
  }

  return <Child onAction={handleAction} />;
}

function Child({ onAction }) {
  return <button onClick={onAction}>Run parent action</button>;
}

React props can carry functions just like other JavaScript values. See Passing Props to a Component and Responding to Events.

As an Amazon Associate I earn from qualifying purchases.

Pass the parent function as a callback prop

When the parent owns an action or state update, it should provide a function prop that gives the child a clear way to request that action. Choose a prop name that describes the event or intent, such as onSave, onChange, or onAction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { useState } from 'react';

function Parent() {
  const [message, setMessage] = useState('Waiting');

  function handleChildAction(value) {
    setMessage(value);
  }

  return (
    <>
      <p>{message}</p>
      <Child onAction={handleChildAction} />
    </>
  );
}

function Child({ onAction }) {
  return (
    <button onClick={() => onAction('Child clicked')}>
      Notify parent
    </button>
  );
}

Here, the parent owns message and its update function. The child receives onAction and calls it when the button is clicked. This keeps the direction of communication explicit: data and functions flow down through props, while a child can invoke a supplied function to request work from above.

Keep shared state in the closest common parent

If a child action changes data that the parent or a sibling also needs, place that state in their closest common parent. Pass the current value down to the components that display it, and pass handlers down to the components that need to request changes. React describes this as lifting state up.

Do not move every piece of state to the top of the application. State used by only one component can stay local. For information needed by many distant components, React Context may be appropriate, but it is unnecessary for a straightforward parent-child callback.

Call the handler when the event happens, not during render

Pass the function itself to the event prop. Writing onClick={handleClick} gives React a handler to call when the click occurs. Writing onClick={handleClick()} calls the function immediately while rendering and passes its return value instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When the callback needs an argument, use a wrapper so the call happens on the event:

<button onClick={() => onAction('Child clicked')}>
  Notify parent
</button>

This follows React’s event-handler guidance: pass handlers rather than invoking them during render. See Responding to Events.

Use a ref only when the parent needs an imperative child operation

The phrase “call a function inside a child from the parent” can also mean that the parent must command a method owned by the child. For operations that are inherently imperative—such as focusing an input or scrolling to a node—a ref can expose a small, deliberate child API. React’s useImperativeHandle lets a component customize what its ref exposes.

Refs are an escape hatch, not a replacement for ordinary props and state. If the behavior can be represented declaratively—for example, with an isOpen prop that controls whether a panel is open—prefer that to exposing imperative methods such as open() and close(). See React’s guidance on manipulating the DOM with refs.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There is a version difference for custom function components: React 19 allows a component to receive ref as a prop; React 18 and earlier require forwardRef to forward a ref. The current useImperativeHandle reference documents this distinction, and React’s forwardRef reference covers the earlier pattern.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Avoid Effects for event callbacks and upward data reporting

Do not add an Effect just to report child data to a parent. If multiple components need the data, let the parent own it and pass values and handlers through props. If the update is caused by a user action, call the callback in that event handler. React explains this in You Might Not Need an Effect.

You also do not need to wrap every callback in useCallback. It caches a function definition between renders, but it is a performance optimization for cases where stable function identity matters, not a requirement for passing a callback prop. See the useCallback reference.

Choose the communication pattern that matches the job

Approach Use it when Tradeoff
Callback prop A child event should ask the parent to perform work or update parent-owned state. Explicit and declarative; the child can invoke the supplied callback.
Ref with useImperativeHandle The parent needs to command a child capability such as focus or scroll. Imperative escape hatch; provides a deliberate API but couples the parent to child commands.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.