completed chapter 6 Hon-Rae #2

Merged
JMR-dev merged 1 commits from jr-completing-ch-6 into main 2021-11-18 21:21:53 +00:00
+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(