Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
React router dom throws invalid hook call, cannot read properties of null, etc
import './interface/App.css';
import { Home } from './interface/home';
import { Router, Route, Routes } from 'react-router-dom';

function App() {
  return ( 
    <div>
      <Router>
        <div>
          <Route exact path='/' component={Home}></Route>
        </div>
      </Router>
    </div>
  );

this throws

enter image description here enter image description here enter image description here

I have no idea why, I was following some tutorials and failed. I have tried using <Home/> instead of Home, I updated all my packages including react, react-dom, react-router-dom.

Any ideas why this is happening?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Issue

You are using react-router-dom@6 and using the low-level Router when you should import and use one of the high-level routers (BrowserRouter, MemoryRouter, etc) and you are using the RRDv5 Route component APIs. The Router component has a couple required props to make it work.

Router

declare function Router(
  props: RouterProps
): React.ReactElement | null;

interface RouterProps {
  basename?: string;
  children?: React.ReactNode;
  location: Partial<Location> | string;
  navigationType?: NavigationType;
  navigator: Navigator;
  static?: boolean;
}

Missing from your code are the required navigator and location props which feed into an internal location context the low-level router holds.

Solution

Import a high-level router, wrap the Route components in the Routes component, and render the routed content on the element prop as a ReactNode, a.k.a. JSX. component (and render and children function props`) are v5 and don't exist in v6.

The high-level routers maintain their own history/location contexts internally.

Example:

import './interface/App.css';
import { Home } from './interface/home';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';

function App() {
  return ( 
    <div>
      <Router>
        <div>
          <Routes>
            <Route path='/' element={<Home />} />
          </Routes>
        </div>
      </Router>
    </div>
  );
}
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!