Props
Master React props — the mechanism for passing data and behaviour between components. Learn prop design, TypeScript typing, and the patterns senior engineers use in real enterprise applications.
Last reviewed: January 2025
🔍 What Is It?
Props are read-only inputs passed to a component from its parent. Every React component receives a single props object. In modern React, we always destructure it in the function signature.
- →Props can be any JavaScript value: strings, numbers, booleans, objects, arrays, functions, or even other React components
- →Props flow one direction only — parent to child (unidirectional data flow)
- →A component must never modify its own props — they are immutable from the component's perspective
- →The
childrenprop is special — it represents the JSX placed between opening and closing tags - →Callback props (functions passed as props) are how children communicate back to parents
🎯 Why Do We Need It?
Props are what make components reusable. Without props, a Button component could only ever say "Click me" with a fixed blue colour. With props, the same Button can say anything, in any colour, trigger any action.
Props enforce unidirectional data flow — data flows down, events flow up. This makes React apps predictable: to understand why a component looks a certain way, you only need to look at the props it received, not the entire application state.
In interviews, this is often asked as: "What is one-way data binding in React?" — props are the answer.
🏗️ What Happens in Real Projects?
Props are used in every component in every React project. Real patterns:
- →Configuration props —
<Button variant="primary" size="lg" loading={isSubmitting} /> - →Data props —
<PolicyCard policy={policyData} /> - →Callback props —
<DataTable onRowClick={handleRowSelect} onSort={handleSort} /> - →Children —
<Modal title="Confirm"><ConfirmationForm /></Modal> - →Render props —
<DataProvider render={(data) => <Chart data={data} />} /> - →Spreading props —
<input {...register('email')} />(React Hook Form)
⚙️ How It Works
When you write <UserCard name="Alice" role="admin" onEdit={handleEdit} />, React calls your UserCard function with { name: "Alice", role: "admin", onEdit: handleEdit } as the argument.
Default props — set with default parameter values in the function signature:
function Button({ variant = 'primary', size = 'md' }: ButtonProps)
Prop spreading — <input {...inputProps} /> passes all properties of an object as individual props. Useful for forwarding HTML attributes.
children prop — anything between opening and closing JSX tags becomes props.children. Type it as React.ReactNode for maximum flexibility.
Prop drilling — passing props through many intermediate layers to reach a deeply nested child. When drilling exceeds 2–3 levels, consider Context or a state manager.
💻 Example
Props Patterns in Production — Typed props, defaults, callbacks, and children patterns used in real projects.
🤔 Common Confusions
❓ What is the difference between props and state?
Props are external inputs — passed from parent, read-only inside the component. State is internal memory — owned and managed by the component itself, can be changed with setState. A component controls its own state but cannot control its own props. Think of props as function arguments and state as local variables.
❓ Can I modify props inside a component?
No. Props are read-only. If you need to derive a value from a prop, compute it inline or with useMemo. If you need to track changes to a prop over time, copy it into local state with useState(initialProp) — but be careful: local state does not automatically sync when the prop changes later.
❓ What is prop drilling and when is it a problem?
Prop drilling is passing props through intermediate components that do not use them — just to get data to a deeply nested child. It becomes a problem at 3+ levels deep: changes to the prop shape require updates in every intermediate component. Solutions: React Context for global data, component composition (render children directly), or Zustand/Redux for complex state.
🚨 Common Production Issues
**Bug: Object/array props causing unnecessary re-renders** — <Component config={{ timeout: 3000 }} /> creates a new object on every parent render, causing the child to re-render even if nothing changed. Fix: define the object outside the component or memoize with useMemo.
**Bug: Mutating props** — Never do props.items.push(newItem). This mutates the parent's data directly, causing unpredictable bugs that are very hard to trace. Always treat props as immutable.
**Bug: Prop drilling through 5+ layers** — Makes refactoring painful and creates tight coupling. Restructure with Context or lift the consuming component higher in the tree.
**Type error: Missing required prop** — TypeScript catches this at compile time but JavaScript will silently pass undefined. Always use TypeScript for prop definitions in production apps.
✅ Best Practices
Always define prop types with TypeScript interfaces — they are the component's public API
Use default parameter values for optional props, not defaultProps (deprecated)
Extend HTML element interfaces when building design system components (InputHTMLAttributes, etc.)
Keep prop lists small — if a component needs 10+ props, it is probably doing too much
Use the children prop for flexible composition instead of a content prop accepting JSX
Document non-obvious props with JSDoc comments — they appear as IDE tooltips
Avoid passing entire objects when only one property is needed — destructure at the call site
🏛️ Architect's Note
The props API of a component is its public contract. Every prop you add is a commitment — removing or renaming it is a breaking change for every consumer. Design prop APIs with the same care you would design a REST endpoint.
In large codebases, the biggest props-related mistake is making components too configurable. A Button with 15 props for every conceivable variation becomes a maintenance nightmare. Instead, create focused variants (PrimaryButton, DangerButton) or use a compound component pattern. Fewer props, clearer intent, easier to maintain.
💬 Frequently Asked Questions
🎯 Key Takeaways
🔗 Related Topics
🎯 Practice this topic in interviews
↗ Where this topic fits
React Technology Guide
Return to the React learning hub.
Frontend Engineer Career Path
A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.
Python Developer Career Path
A practical route through Python fundamentals, automation, backend basics, testing, projects, interview preparation, and career growth.
Sources
Sources / References
Use these React references to verify the concept in official docs and continue into the most relevant SplashRide pages.
Official documentation
Related SplashRide pages
SplashRide React learning path
Browse the full React topic collection and learning order on SplashRide.
React Interview Prep
Practice React interview questions and scenario-based answers.
Frontend Engineer Career Path
A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.
Python Developer Career Path
A practical route through Python fundamentals, automation, backend basics, testing, projects, interview preparation, and career growth.
Components
Master React components — the fundamental building blocks of every React application. Learn component design, composition patterns, and how senior engineers structure components in enterprise projects.
JSX
Understand JSX — the syntax extension that makes React feel like writing HTML in JavaScript. Learn how it compiles, what rules it enforces, and how senior engineers use it in production.