completed chapter 6 Hon-Rae

This commit is contained in:
2021-11-18 15:20:23 -06:00
parent 96c5b812e3
commit 6bc66e066b
+5 -8
View File
@@ -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 (
<>
<div>
Specialties:
Specialties: { specialties }
</div>
{
employees.map(