diff --git a/src/components/EmployeesList.js b/src/components/EmployeesList.js index e1a4796..1e736c6 100644 --- a/src/components/EmployeesList.js +++ b/src/components/EmployeesList.js @@ -1,8 +1,8 @@ -import React, { useEffect, useState } from "react" +import React, { useEffect, useState, } from "react" export const EmployeeList = () => { const [employees, changeEmployee] = useState([]) - + const [specialties, setSpecial] = useState("") useEffect( () => { fetch("http://localhost:8088/employees") @@ -15,17 +15,14 @@ export const EmployeeList = () => { ) useEffect(() => { - /* - 1. Use .map() to get the specialty of each employee - 2. Then update a state variable to be a comma-separated string - (e.g. "iPhone, Printers, ...") - */ + const justSpecialities = employees.map(emp => emp.specialty) + setSpecial(justSpecialities.join(", ")) }, [employees]) return ( <>