π React Lists: A Beginner-Friendly Guide to Rendering Collections
π React Lists: A Beginner

Working with lists is one of the most common tasks in React. Whether you're displaying products, users, messages, or notifications, lists make your UI dynamic.
In this Hasenode-style blog, weβll explore how lists work in React, why keys are important, and best practices every React developer must know.
π₯ What Are Lists in React?
In JavaScript, we often work with arrays. In React, we use arrays + JSX to render UI elements repeatedly.
For example:
Showing a list of users
Mapping through products
Displaying comments
Rendering menu items
React uses the map() function to loop through arrays and return JSX.
π§© Rendering a Basic List in React
Hereβs the simplest example of rendering a list:
function FruitList() {
const fruits = ["Apple", "Banana", "Mango"];
return (
<ul>
{fruits.map((fruit, index) => (
<li key={index}>{fruit}</li>
))}
</ul>
);
}
export default FruitList;
π Whatβs happening here?
We created an array
We used
map()to convert each fruit into an<li>elementWe added a key, which React needs for efficient rendering
ποΈ Understanding Keys in React Lists
Keys help React identify list items and track changes efficiently.
β Wrong: Using index as key (in dynamic lists)
<li key={index}>{item}</li>
Using index can cause problems when:
List items change order
Items are added or removed
βοΈ Correct: Use a unique ID when possible
const users = [
{ id: 1, name: "Amit" },
{ id: 2, name: "Priya" },
{ id: 3, name: "John" }
];
function UserList() {
return (
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
π§± Rendering List of Components
Lists donβt have to render plain text β they can render entire components.
Example:
function User({ name }) {
return <p>{name}</p>;
}
function UserList() {
const users = ["Amit", "Rahul", "Sneha"];
return (
<>
{users.map((user, idx) => (
<User key={idx} name={user} />
))}
</>
);
}
This improves separation of concerns and makes components reusable.
π Common Mistakes With Lists
β Missing keys
β Using duplicate keys
β Using array index as key (for dynamic lists)
β Adding key inside component instead of where list is rendered
Correct placement:
βοΈ Key should be placed where .map() returns the element.
π§ When Should You Use Index as a Key?
Index is okay only if:
List is static
Items will NOT be reordered
No items will be added/removed
Example use-case:
Rendering a static menu with fixed options.
π‘ Pro Tip: Always Keep Data + UI Separate
Instead of embedding logic inside JSX, keep arrays clean:
const menuItems = ["Home", "About", "Contact"];
Then map them into JSX.
This keeps components readable and maintainable.
π― Final Thoughts
React Lists are simple yet powerful.
By understanding .map(), keys, and best practices, you can build clean, dynamic UIs with ease.



