What are props and how is prop drilling a problem?
Hint
Props pass data down; drilling = passing through many layers just to reach a deeply nested child
Full Answer
Props are the inputs to a component — passed from parent to child. They are read-only (immutable from the child's perspective).
function Button({ label, onClick, disabled = false }) {
return <button onClick={onClick} disabled={disabled}>{label}</button>;
}
// Usage
<Button label="Save" onClick={handleSave} disabled={isLoading} />
Prop drilling — passing props through intermediate components that don't need them, just so a deep child can access them:
// ❌ Drilling — Middle doesn't need user, just passes it down
function App() {
const user = { name: 'Alice' };
return <Middle user={user} />;
}
function Middle({ user }) {
return <Deep user={user} />;
}
function Deep({ user }) {
return <p>{user.name}</p>;
}
Solutions to prop drilling:
- Context API — broadcast value to any descendant
- Component composition — lift rendering up, pass JSX as children or slots
- State management — Zustand, Redux, Jotai for global state
💡 Before reaching for Context, try composition first. Pass
children or render props — often eliminates drilling without the overhead of a context.More React Fundamentals Questions
Practice this in a timed sprint
5 free questions, no signup required