Passing array of objects through Props in React.js | Pluralsight

PHOTO EMBED

Thu Jul 21 2022 08:17:12 GMT+0000 (Coordinated Universal Time)

Saved by @Harsh_S ##array ##object ##prop ##react

1constructor() {
2    super();
3    this.state = {
4      employees: [
5        {
6          firstname: "FirstName123",
7          lasttname: "LastName123"
8        },
9        {
10          firstname: "FirstName456",
11          lasttname: "LastName456"
12        }
13      ]
14    };
15}

1render() {
2    const { employees } = this.state;  //Destructuring
3
4    return (
5      <div>
6        <div>
7          {employees.map(employee => (
8            <p key={employee.firstname}>
9              {employee.firstname} : {employee.lasttname}
10            </p>
11          ))}
12        </div>
13      </div>
14    );
15}
content_copyCOPY

https://www.pluralsight.com/guides/accessing-data-through-props-with-known-key-names-in-reactjs