React: useLocation Hook doesn't exist in react-router-dom Typescript

Viewed 6739

Hello I'm trying to import useLocation Hook from react-router-dom "typescript" I can't find it

as per React Router Documentation I'm pretty sure it exists.

Yet in typescript it keeps telling me there is not exported member called useLocation

This is how I import it:

import { useLocation } from 'react-router-dom';

And this is the error I get:

Module '"../../node_modules/@types/react-router-dom"' has no exported member 'useLocation'.ts(2305)

3 Answers

This is a typescript parsing error meaning the error is thrown by the package @types/react-router-dom and not the package react-router-dom, make sure you update and reinstall both.

Make sure to have both react-router-dom and @types/react-router-dom in version 5.x

npm i react-router-dom@5
npm i -D @types/react-router-dom@5

I also have the same challenge, running the following command resolved the problem

npm i --save-dev @types/react-router-dom 
Related