ScanSkill

Lists

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.

Syntax

array.map((item) => <Component props={item} />)

Example

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>
    </>
  );
}
lists