From 6bc66e066b90dff0a41de11f46230024d5c119d4 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Thu, 18 Nov 2021 15:20:23 -0600 Subject: [PATCH] completed chapter 6 Hon-Rae --- src/components/EmployeesList.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 ( <>
- Specialties: + Specialties: { specialties }
{ employees.map( -- 2.47.3