Archived
completed chapter 6 Hon-Rae
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user