Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

300
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda