Passing Props to Components
Learn how to pass data from a parent component to child components using props, with diagrams, examples and expected browser output.
01 What Are Props?
Props stands for properties. Props allow a parent component to send information to a child component. A child component receives this information through its props parameter.
02 Passing a Single String Prop
A string can be passed by writing a property name and value inside the child component's opening tag.
function App() {
return <Student name="Samadhan" />;
}
function Student(props) {
return <h2>Student Name: {props.name}</h2>;
}
export default App;
How it works:
Appis the parent component.name="Samadhan"passes a string prop.props.namereads that value in the child.
Student Name: Samadhan
03 Passing Multiple Props
You can pass more than one prop to a component. For example, a student component can receive a name, course and duration.
function App() {
return (
<Student
name="Samiksha"
course="React JS"
duration="3 Months"
/>
);
}
function Student(props) {
return (
<div>
<h2>{props.name}</h2>
<p>Course: {props.course}</p>
<p>Duration: {props.duration}</p>
</div>
);
}
export default App;
Samiksha
Course: React JS
Duration: 3 Months
04 Passing Numbers and Boolean Values
Use curly braces to pass JavaScript values such as numbers and booleans. A string written without curly braces is treated as text.
function App() {
return (
<Student
name="Pradnya"
age={22}
enrolled={true}
/>
);
}
function Student(props) {
return (
<div>
<p>Name: {props.name}</p>
<p>Age: {props.age}</p>
<p>
Status: {props.enrolled ? "Enrolled" : "Not Enrolled"}
</p>
</div>
);
}
export default App;
Name: Pradnya
Age: 22
Status: Enrolled
05 Passing an Array as Props
Arrays can also be passed as props. The child component can use
the JavaScript map() method to display each item.
function App() {
const skills = ["HTML", "CSS", "JavaScript"];
return <Student name="Samadhan" skills={skills} />;
}
function Student(props) {
return (
<div>
<h3>{props.name}'s Skills</h3>
<ul>
{props.skills.map((skill) => (
<li key={skill}>{skill}</li>
))}
</ul>
</div>
);
}
export default App;
Samadhan's Skills
- HTML
- CSS
- JavaScript
06 Passing an Object as Props
An object groups related values into one structure. You can pass the complete object through a prop and access its properties inside the child component.
function App() {
const student = {
name: "Pradnya",
course: "Full Stack Development",
institute: "CIIT Training Institute"
};
return <Student details={student} />;
}
function Student(props) {
return (
<div>
<h3>{props.details.name}</h3>
<p>Course: {props.details.course}</p>
<p>Institute: {props.details.institute}</p>
</div>
);
}
export default App;
Pradnya
Course: Full Stack Development
Institute: CIIT Training Institute
07 Props in Reusable Components
Props make components reusable. Instead of creating a separate component for every course, create one Course component and pass different values to it.
function App() {
return (
<div>
<Course name="Java" duration="4 Months" />
<Course name=".NET" duration="5 Months" />
<Course name="Python" duration="3 Months" />
</div>
);
}
function Course(props) {
return (
<div>
<h3>{props.name}</h3>
<p>Duration: {props.duration}</p>
</div>
);
}
export default App;
Java
Duration: 4 Months
.NET
Duration: 5 Months
Python
Duration: 3 Months
08 Passing Props Through Components
Sometimes data is passed through an intermediate component before reaching the component that displays it. Passing props through multiple levels like this is often called prop drilling.
function App() {
return <Student name="Samiksha" />;
}
function Student(props) {
return <StudentProfile name={props.name} />;
}
function StudentProfile(props) {
return <h2>Welcome to CIIT, {props.name}!</h2>;
}
export default App;
Welcome to CIIT, Samiksha!
09 Props Are Read-Only
Props should not be changed directly inside a child component. If a value needs to change in response to user interaction, React state is usually the appropriate approach.
// Incorrect: do not modify props directly.
function Student(props) {
// props.name = "Pradnya";
return <h2>{props.name}</h2>;
}
When the parent passes name="Samadhan":
Samadhan
The child displays the received value without modifying it.
10 Complete Props Example
This example combines strings, numbers and an array to display a student profile.
function App() {
const skills = ["React JS", "JavaScript", "HTML"];
return (
<StudentProfile
name="Samadhan"
age={23}
skills={skills}
/>
);
}
function StudentProfile(props) {
return (
<div>
<h2>Student Profile</h2>
<p>Name: {props.name}</p>
<p>Age: {props.age}</p>
<h3>Skills</h3>
<ul>
{props.skills.map((skill) => (
<li key={skill}>{skill}</li>
))}
</ul>
</div>
);
}
export default App;
Student Profile
Name: Samadhan
Age: 23
Skills
- React JS
- JavaScript
- HTML
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.