React User Profiles List using Props and map()
๐ INTRODUCTION
Displaying lists of users is a very common requirement in modern web applications like:
- Social media apps
- Admin dashboards
- Student portals
In this program, we will:
- Create a User Profile Component
- Pass user data using props
- Render multiple profiles using map()
๐ This is a real-world React concept and very important for projects.
๐ PROBLEM STATEMENT
๐ Design a React component to display a list of user profiles, accepting a prop named profiles.
๐ก CONCEPTS USED
- React Props
- List Rendering (
map()) - Component Reusability
- JSX
๐ง LOGIC EXPLANATION
- Create a UserProfile component
- Pass profile data using props
- Use
map()to render multiple profiles - Display name, email, and image
๐ป PROGRAM CODE
Step 1: Create UserProfile Component
function UserProfile({ name, email, image }) {
return (
<div style={styles.card}>
<img src={image} alt={name} style={styles.image} />
<h3>{name}</h3>
<p>{email}</p>
</div>
);
}
const styles = {
card: {
border: "1px solid #ddd",
borderRadius: "10px",
padding: "15px",
width: "200px",
textAlign: "center",
margin: "10px"
},
image: {
width: "80px",
height: "80px",
borderRadius: "50%"
}
};
export default UserProfile;
Step 2: Use in App.js
import UserProfile from "./UserProfile";
function App() {
const profiles = [
{
id: 1,
name: "Kavita",
email: "kavita@gmail.com",
image: "https://via.placeholder.com/80"
},
{
id: 2,
name: "Amit",
email: "amit@gmail.com",
image: "https://via.placeholder.com/80"
}
];
return (
<div>
<h1>User Profiles</h1>
<div style={{ display: "flex" }}>
{profiles.map(profile => (
<UserProfile
key={profile.id}
name={profile.name}
email={profile.email}
image={profile.image}
/>
))}
</div>
</div>
);
}
export default App;
๐ฅ๏ธ OUTPUT
User Profiles
[Profile Card] [Profile Card]
Kavita Amit
kavita@gmail.com amit@gmail.com
๐ STEP-BY-STEP EXPLANATION
profilesโ array of user objectsmap()โ loops through profiles<UserProfile />โ reusable componentkey={profile.id}โ unique identifier
โก ADVANCED FEATURES
1. Add More Fields
{profile.phone}
{profile.address}
2. Add Button
<button>View Profile</button>
3. Add Grid Layout
<div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)" }}>
๐ฏ WHY THIS PROGRAM IS IMPORTANT
- Combines props + map()
- Builds real-world UI
- Helps in API data rendering
- Common interview question
๐ REAL-WORLD USE CASE
- Student management systems
- Employee dashboards
- Social media apps
- Contact directories
โ VIVA QUESTIONS (IMPORTANT)
Q1. What is props in React?
๐ Props are used to pass data between components.
Q2. Why use map() in React?
๐ To render lists dynamically.
Q3. What is key in React?
๐ A unique identifier for list items.
Q4. What is reusable component?
๐ A component used multiple times with different data.
Q5. Can we pass objects as props?
๐ Yes, objects and arrays can be passed.
๐ RELATED POSTS
๐ MCA 168 Full Stack Development Lab Programs List
๐ React Todo Component โ Program 12
๐ React Product Card โ Program 11
๐ React List Rendering โ Program 7
๐ CONCLUSION
The User Profiles List demonstrates how React efficiently handles dynamic data and reusable components.
๐ Master this concept to build scalable and dynamic applications.
Further Reading
How to Master Full Stack Development?
Spring Framework Practice Problems and Their Solutions
From Google to the World: The Story of Go Programming Language
Why Go? Understanding the Advantages of this Emerging Language
Creating and Executing Simple Programs in Go
20+ Interview Questions on Go Programming Language
100+ MCQs On Java Architecture
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
