Map Function in ReactJs
1 min readMay 9, 2025
π React Notes β 3 Ways to Use .map() to Render Components
Press enter or click to view image in full size![]()
first way=> {users.map((user)=><User {...user}/>)}
second way=> {{users.map((user)=>{
return <User {...user}/>})}
third way=>{users.map((user)=>(
<User {...user}/>
))}const users = [
{ firstName: "Aarav", lastName: "Sharma", city: "Delhi" },
{ firstName: "Sneha", lastName: "Patel", city: "Ahmedabad" },
{ firstName: "Rohan", lastName: "Mehta", city: "Mumbai" },
{ firstName: "Isha", lastName: "Verma", city: "Bangalore" },
{ firstName: "Kunal", lastName: "Thakur", city: "Pune" }
];β 1. Short Syntax β Arrow Function with Implicit Return
{users.map((user) => <User {...user} />)}- Most concise way
- No
returnkeyword needed - Best for single-line rendering
Get Kirti Mahajanβs stories inΒ yourΒ inbox
Join Medium for free to get updates fromΒ thisΒ writer.
β
2. Arrow Function with return
{users.map((user) => {
return <User {...user} />;
})}- Use when you need more logic inside the function
- Allows multiline code
β 3. Classic Example (Commented) without return
{/* {users.map((user) => (
<User {...user} />)
)} */}- Same as example 1, just commented for reference
π‘ Always add a key prop in real-world usage with ( ) brackests
{users.map((user, index) => (
<User key={index} {...user} />
))}



