I am trying to import useHistory from 'react-router-dom', however, I get this error: import error: 'useHistory' is not exported from 'react-router-dom'.
I have checked other answers as well such as Attempted import error: 'useHistory' is not exported from 'react-router-dom' this but to no avail. My package.json looks like this
I am using useHistory as such,
import React from 'react';
import { useState, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
export default function Login(){
const history = useHistory();
console.log(history)
}
However, this line works fine and does not cause import issues from react-router-dom.
import {BrowserRouter as Router, Switch, Route} from 'react-router-dom'
Does anyone have an idea how to solve this issue? much appreciated.
I am trying to import useHistory from 'react-router-dom', however, I get this error: import error: 'useHistory' is not exported from 'react-router-dom'.
I have checked other answers as well such as Attempted import error: 'useHistory' is not exported from 'react-router-dom' this but to no avail. My package.json looks like this
I am using useHistory as such,
import React from 'react';
import { useState, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
export default function Login(){
const history = useHistory();
console.log(history)
}
However, this line works fine and does not cause import issues from react-router-dom.
import {BrowserRouter as Router, Switch, Route} from 'react-router-dom'
Does anyone have an idea how to solve this issue? much appreciated.
Share Improve this question edited Sep 19, 2021 at 19:10 TanDev asked Sep 19, 2021 at 2:05 TanDevTanDev 4373 gold badges8 silver badges15 bronze badges 3-
Is your
Login
ponent's route wrapped insideBrowserRouter
? – Sanket Shah Commented Sep 19, 2021 at 2:13 - Yes it actually is. – TanDev Commented Sep 19, 2021 at 18:27
- why are you reassigning window.history? – Nikos Commented Aug 3, 2022 at 7:33
4 Answers
Reset to default 14UseHistory have already been replaced with useNavigate So try this