export 'usehistory' (imported as 'usehistory') was not found in 'react-router-dom'

You may face export 'usehistory' (imported as 'usehistory') was not found in 'react-router-dom error because of wrong react-router-dom version.

You can easily fix this error by correcting react-router-dom version.

You can follow below instrutions to solve export 'usehistory' (imported as 'usehistory') was not found in 'react-router-dom' error.

Instructions

  1. go to package.json file
  2. check react-router-dom package version.
  3. if version is 5 or less then its incorrect version use v6 or above
  4. use command in terminal npm i [email protected] or yarn add [email protected]
  5. once you insatll latest package, you can use useNavigate instead of usehistory
import { useNavigate } from 'react-router-dom';
const navigate = useNavigate();
navigate('/home');

this is the latest way to navigate website pages.

Related Articles

js interview questions