How to properly use useHistory () from react-router-dom?

This has changed in v6, useHistory is now useNavigate and we can use it as follows:

instead of:

const history = useHistory()
history.push("https://stackoverflow.com/")

we now use:

const navigate = useNavigate()
navigate("https://stackoverflow.com/")

Leave a Comment