I want to automatic redirect home page after click on update button, here is my handleSubmit
code:
const handleSubmit = (e) => {
e.preventDefault();
// access data from backend
axios
.put(`${process.env.REACT_APP_API}/post/${slug}`, {
title,
content,
user,
})
.then((response) => {
console.log(response);
const { title, content, slug, user } = response.data;
setState({ ...state, title, content, slug, user });
alert(`Post Title ${response.data.title} is Updated`);
})
.catch((error) => {
console.log(error.response);
});
};
Here I have use a alert when my post has been updated then show me, but now I need to redirect my home page. when I click on update
button
Any suggestion please.