What Are Props in React?
Understand how React components receive data from parent components, use props to display dynamic information, and build reusable UI at CIIT Training Institute.
01 Learning Objectives
After completing this lesson, you will be able to:
Understand the purpose of props in React.
Understand how components communicate through props.
Use received values in JSX output.
Follow the read-only rule and reuse components.
02 Definition of Props
Props stands for properties. In React, props are inputs passed from a parent component to a child component. The child uses these values to decide what content to render.
function Welcome(props) {
return (
<h2>Welcome, {props.name}!</h2>
);
}
export default Welcome;
import Welcome from "./Welcome";
function App() {
return <Welcome name="Samadhan" />;
}
export default App;
Welcome, Samadhan!
03 Parent and Child Components
A parent component can pass values to a child through JSX attributes. React makes those values available to the child through its props parameter.
name="Samiksha"
props.name
function Welcome(props) {
return <h2>Welcome, {props.name}!</h2>;
}
function App() {
return <Welcome name="Samiksha" />;
}
export default App;
Welcome, Samiksha!
The parent passes the name value to the Welcome component.
04 Accessing Props in a Component
A function component can receive a props object as its parameter.
You can access individual values using dot notation, such as
props.name and props.course.
function StudentInfo(props) {
return (
<div>
<h2>{props.name}</h2>
<p>Course: {props.course}</p>
</div>
);
}
export default StudentInfo;
import StudentInfo from "./StudentInfo";
function App() {
return (
<StudentInfo
name="Pradnya"
course="React JS"
/>
);
}
export default App;
Pradnya
Course: React JS
05 Different Types of Prop Values
Props can contain strings, numbers, booleans, arrays, objects, functions and other JavaScript values. Use quotation marks for string attributes and curly braces for JavaScript expressions.
function CourseInfo(props) {
return (
<div>
<h2>{props.name}</h2>
<p>Duration: {props.months} months</p>
<p>Online: {props.isOnline ? "Yes" : "No"}</p>
</div>
);
}
export default CourseInfo;
import CourseInfo from "./CourseInfo";
function App() {
return (
<CourseInfo
name="React JS"
months={3}
isOnline={true}
/>
);
}
export default App;
React JS
Duration: 3 months
Online: Yes
months={3} passes a number, while
months="3" passes a string. Use curly braces
when passing JavaScript values or expressions.
06 Props Make Components Reusable
A single component can be rendered several times with different props. This avoids duplicating the same component structure for every student or course.
function StudentCard(props) {
return (
<div>
<h3>{props.name}</h3>
<p>Course: {props.course}</p>
</div>
);
}
export default StudentCard;
import StudentCard from "./StudentCard";
function App() {
return (
<section>
<h2>CIIT Student Profiles</h2>
<StudentCard
name="Samadhan"
course="React JS"
/>
<StudentCard
name="Samiksha"
course=".NET Full Stack"
/>
<StudentCard
name="Pradnya"
course="Python"
/>
</section>
);
}
export default App;
CIIT Student Profiles
07 Props Are Read-Only
React components should not modify the props they receive. If a value needs to change, the parent should pass updated data, or the component should use state for its own changing data.
function Greeting(props) {
return (
<div>
<h2>Hello, {props.name}!
<p>Welcome to CIIT Training Institute.</p>
</div>
);
}
export default Greeting;
props.name, but do not assign
a new value to props.name. Treat props as read-only
inputs to keep component behaviour predictable.
Hello, Samiksha!
Welcome to CIIT Training Institute.
08 Props vs Hardcoded Values
A hardcoded component displays fixed content. A component that uses props can display different content without changing the component's internal code.
| Hardcoded Component | Component Using Props |
|---|---|
| Displays fixed content. | Displays content supplied by the parent. |
| Needs code changes to show another name. | Can display another name by receiving a new prop. |
| Less flexible for repeated UI. | Supports reusable UI with different data. |
function Welcome(props) {
return <h2>Welcome, {props.name}!</h2>;
}
export default Welcome;
Using <Welcome name="Samadhan" />:
Welcome, Samadhan!
Using <Welcome name="Pradnya" />:
Welcome, Pradnya!
09 Common Props Mistakes
1. Incorrect Prop Name
Ensure the attribute name passed by the parent matches the property accessed by the child.
<Welcome name="Samadhan" />
2. Passing a Number as a String
Use curly braces when you need to pass a number rather than a string.
<Student marks={80} />
3. Modifying Props
Props are read-only. Do not assign a new value to a prop inside the child component.
return <p>{props.name}</p>;
4. Forgetting to Pass a Required Value
If a component expects a value, make sure the parent provides it or the component has a suitable fallback.
<StudentInfo name="Pradnya" />
10 Practice Questions
- What are props in React?
- How does a parent component pass data to a child component?
- Create a Welcome component that accepts a name prop.
- Pass a number and a boolean to a component.
- Create a CourseInfo component with name and duration props.
- Build reusable StudentCard components for Samadhan, Samiksha and Pradnya.
- Why should a component treat props as read-only?
Summary
Props are inputs that allow a parent component to pass data to a child component. They can contain strings, numbers, booleans, arrays, objects and functions. Components use props to display dynamic content and reuse the same UI with different data. Props should be treated as read-only, helping React applications remain predictable and maintainable at CIIT Training Institute.