Correction to function param and added redirect to home after edit

This commit is contained in:
Andrew Scott 2022-06-04 03:20:01 -04:00
parent ec4f910562
commit 552187d53e
Signed by: a
GPG key ID: 3EB62D0BBB8DB381

View file

@ -4,9 +4,11 @@ import { Link } from "react-router-dom";
import { useHistory } from "react-router-dom";
import "../App.css";
function HomePage() {
function HomePage({ setExerciseToEdit }) {
const [exercises, setExercises] = useState([]);
const history = useHistory();
const onDelete = async (_id) => {
const response = await fetch(`/exercises/${_id}`, { method: "DELETE" });
if (response.status === 204) {
@ -19,8 +21,8 @@ function HomePage() {
};
const onEdit = async (exerciseToEdit) => {
//setExerciseToEdit(exerciseToEdit);
//history.push("/edit");
setExerciseToEdit(exerciseToEdit);
history.push("/edit");
};
const loadExercises = async () => {
@ -41,7 +43,7 @@ function HomePage() {
onDelete={onDelete}
onEdit={onEdit}
></ExerciseList>
<div className="App-link">
<div>
<Link to="/create">Create</Link>
</div>
</div>