Using this code :
import { Link, useHistory } from "react-router-dom";
...
const history = useHistory();
...
history.push("/login");
This error shows up :

Is useHistory obsolete ? Or I do need to use another function ?
Yes it is depreciated in V6 of react-router. In this version to navigate use the useNavigate hook. Check the docs here React Router V6 API Reference. Or more specifically the useNavigate hook here React Router v6 UseNavigate Hook. So like so:
import { useNavigate } from 'react-router-dom'
const navigate = useNavigate()
navigate('/login')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With