I'm doing a meetup app and I want to go back to the main page after the data is submitted, Here is my code:
import { useNavigate } from "react-router-dom";
import NewMeetupForm from "../components/meetups/NewMeetupForm";
function NewMeetupsPage() {
const navigate = useNavigate();
function addMeetupHandler(meetupData) {
fetch(
"https://react-meetup-app-aad0d-default-rtdb.firebaseio.com/meetups.json",
{
method: "POST",
body: JSON.stringify(meetupData),
headers: {
"Content-Type": "application.json",
},
}
).then(() => {
navigate.replace("/");
});
}
return (
<section>
<h1>Add New Meetup</h1>
<NewMeetupForm onAddMeetup={addMeetupHandler} />
</section>
);
}
As you can see I used a
.then(() => {
navigate.replace("/");
});
but when I submit the info, I get this error: Unhandled Rejection (TypeError): navigate.replace is not a function
I know on v6 alotta things have changed, is that the case here or, am I missing something?