Search code examples
reactjsintellij-ideareact-routerimporterrorreact-router-dom

Why does IntelliJ does not auto import react router hooks?


From v5.1 the react router supports hook. I have "react-router-dom": "^5.1.2" in my package.json but when typing useRouterMatch in my component, IntelliJ does not suggest to auto import import {useRouteMatch} from "react-router-dom";

When adding the import manually everything works, but that's pretty inconvenient.


Solution

  • I figured out that IntelliJ seems to index packages based on package.json. The actual hooks are implemented in react-router.

    Since react-router is a dependency of react-router-dom and added to node_modules it seems not to be indexed by IntelliJ. The solution is to also add react-router to package.json:

    "react-router": "^5.1.2",
    "react-router-dom": "^5.1.2",