-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllDeer.js
46 lines (37 loc) · 1.12 KB
/
AllDeer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { useEffect, useState } from 'react';
import { useNavigate } from "react-router-dom";
import "./AllDeer.css"
import { DeerProfile } from "./DeerProfile";
export const AllDeer = () => {
const [deerList, setDeerList] = useState([]);
const navigate = useNavigate();
const getAllDeerProfiles = () => {
fetch("http://localhost:8088/deer")
.then((response) => response.json())
.then((deerArray) => {
setDeerList(deerArray);
});
};
const deleteDeerProfile = (singleDeer) => {
return fetch(`http://localhost:8088/deer/${singleDeer.id}`, {
method: 'DELETE'
})
.then(() => {
getAllDeerProfiles();
})
};
useEffect(() => {
getAllDeerProfiles();
}, []);
return (
<>
<button onClick={() => navigate("/deer/create")}>Add New Deer Profile</button>
<h2>List of Deer Profiles</h2>
<article className="deerProfiles">
{deerList.map((deer) => (
<DeerProfile key={deer.id} deerObject={deer} onDelete={deleteDeerProfile} />
))}
</article>
</>
);
};