How do you pass data from child to parent in React?
BeginnerReact interview questionBy UIRound, updated 17 November 2026
Short answer
Data in React flows down through props, so a child cannot write to its parent directly. Instead, the parent passes a function as a prop, and the child calls that function with the data, usually from an event handler. The parent then stores the data in its own state. For shared values this is lifting state up; for distant components use context or a store.
Callback props
import { useState } from "react";
function SearchPage() {
const [query, setQuery] = useState("");
return (
<>
<SearchBox onSearch={setQuery} />
<Results query={query} />
</>
);
}
function SearchBox({ onSearch }) {
const [text, setText] = useState("");
function handleSubmit(event) {
event.preventDefault();
onSearch(text.trim()); // the child sends data up
}
return (
<form onSubmit={handleSubmit}>
<input value={text} onChange={(e) => setText(e.target.value)} />
<button type="submit">Search</button>
</form>
);
}SearchBox does not know or care what the parent does with the query. It only promises to call onSearch when the user submits. The parent stores the query and passes it down to Results. This is one-way data flow: data goes down as props, events go up as function calls.
Name callback props after the event, starting with on: onSearch, onSelect, onChange. The name says what happened in the child, not what the parent will do about it.
Lifting state up
Sometimes the parent should own the value outright, not receive a copy of it. If two siblings need the same data, move the state to their closest common parent, pass the value down and pass a setter or callback down with it. The child becomes controlled:
function Filters() {
const [category, setCategory] = useState("all");
return (
<>
<CategoryPicker value={category} onChange={setCategory} />
<ProductList category={category} />
</>
);
}
function CategoryPicker({ value, onChange }) {
return (
<select value={value} onChange={(e) => onChange(e.target.value)}>
<option value="all">All</option>
<option value="books">Books</option>
<option value="games">Games</option>
</select>
);
}CategoryPicker holds no state at all. There is one source of truth, so the picker and the list can never disagree. What does lifting state up mean in React? walks through when to lift and how far.
Choosing an approach
| Situation | Approach |
|---|---|
| Child reports an event or a final value (submit, select) | Callback prop |
| Parent and siblings need the live value | Lift state up; make the child controlled |
| Parent needs to tell the child to do something (focus, reset, scroll) | A ref, with useImperativeHandle |
| Components are many levels apart | Context with a setter, or a state library |
| Data is fetched from a server and used in several places | A server-state cache such as TanStack Query |
Refs for imperative cases
Occasionally the parent needs to call a method on the child, such as "focus your first invalid field" or "reset". That is not data flowing up; it is the parent reaching down. In React 19, ref is an ordinary prop for function components, and useImperativeHandle chooses what the parent sees:
import { useImperativeHandle, useRef } from "react";
function SearchInput({ ref }) {
const inputRef = useRef(null);
useImperativeHandle(ref, () => ({
focus: () => inputRef.current.focus(),
clear: () => { inputRef.current.value = ""; },
}), []);
return <input ref={inputRef} />;
}
function Toolbar() {
const searchRef = useRef(null);
return (
<>
<SearchInput ref={searchRef} />
<button onClick={() => searchRef.current.focus()}>Find</button>
</>
);
}Expose a small set of commands, not the whole DOM node. Use this only when props cannot express the behaviour: if "open" is a state, pass isOpen as a prop instead. How does forwardRef work, and what changed in React 19? covers the ref changes.
Far away: context or a store
If the component that produces the data is deep in the tree and the one that needs it is far away, passing callbacks through every level becomes prop drilling. Put the state and its setter in a context provider near the top, and any descendant can call the setter. For state that changes often and is read in many places, a store with selectors avoids re-rendering every consumer.
Before reaching for either, check whether passing elements as children would remove the intermediate layers. It often does.
Practise it
Build a list of independent counters has the parent own every count and receive changes through callbacks. Build linked inputs without effect loops is lifting state up done properly, and Build a component that works both controlled and uncontrolled covers the value and onChange contract. Expose one command with useImperativeHandle trains the ref case.
Common follow-up questions
Can a child change its props?
No. Props are read-only for the component that receives them. The child asks the owner to change the value by calling a callback, and the owner re-renders with new props. See State vs props in React.
Should I call the parent's callback in a useEffect?
useEffect?Usually not. Code like useEffect(() => onChange(value), [value]) runs after an extra render and can loop if the parent updates the child in response. Call the callback in the event handler that caused the change, at the same moment you update local state.
Does passing a new callback on every render hurt performance?
Rarely. It matters only when the child is wrapped in memo and is expensive to render. Then wrap the callback in useCallback so its identity stays stable.
Can a child pass data to a sibling directly?
No. Siblings communicate through their shared parent: one child calls a callback, the parent updates state, and the other child receives it as a prop.
Mistakes to avoid
Copying a prop into the child's state and expecting the parent to see changes
Syncing child state to the parent with an effect instead of calling the callback in the handler
Calling the callback during render, which updates the parent while React is rendering
Using a ref to read a child's data when a callback prop would do
Drilling a setter through five layers instead of using composition or context
Sources
Practise it in code
Interviewers rarely stop at the definition. These questions open in an editor with tests.
- Build a list of independent counters: add, remove and reset, with a derived totalMedium30 min
- Build linked inputs without effect loops: a Celsius/Fahrenheit converter and a recipe scalerMedium35 min
- Expose one command with
useImperativeHandle:focusFirstInvalid()andreset()Medium30 min - Build a component that works both controlled and uncontrolledMedium30 min