React — Rendering Lists
You can use JavaScript's map()
function to render lists of elements in React. Each element in the list should have a unique key
prop.
function NameList() {
const names = ['Alice', 'Bob', 'Charlie'];
return (
<ul>
{names.map((name, index) => (
<li key={index}>{name}</li>
))}
</ul>
);
}