In React, we can list the elements of an array in a component. The JavaScript map()
method is the most used method to list the elements of an array.
array.map((item) => <Component props={item} />)
function Student(props) {
return <li>My name is { props.name }</li>;
}
function Example() {
const students = ['John', 'Billy', 'Will'];
return (
<>
<h1>List of students</h1>
<ul>
{students.map((student) => <Student name={student} />)}
</ul>
</>
);
}