cannot read property of undefined (reading ‘push’) react
import { useHistory } from "react-router-dom"; let history = useHistory(); history.push('/asdfg') It will Work Now!
Here is what the above code is Doing:
1. We are importing the useHistory hook from the react-router-dom library.
2. We are creating a history variable and assigning it to the useHistory hook.
3. We are using the push method to redirect the user to the /asdfg route.