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

246
Vistas
unable to define navigate = useNavigate()

I'm trying to run this code:

  const navigate = useNavigate()
  <div>
    <button onClick={() => navigate("/")}>CLICK</button>
    <h1>HATS PAGE</h1>
  </div>
);

but somehow const navigate = useNavigate() gives me Parsing error: Unexpected token

Could anyone please help me with this problem?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can't put your statements which define variables in the middle of a JSX expression.

Define your variables first. Then do your JSX.

const navigate = useNavigate();

return (
    <div>
        <button onClick={() => navigate("/")}>CLICK</button>
        <h1>HATS PAGE</h1>
    </div>
);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Hooks need to be called at the top level of your React functional component.

function ComponentName() {
  const navigate = useNavigate();

  return (
    <div>
    <button onClick={() => navigate("/")}>CLICK</button>
      <h1>HATS PAGE</h1>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza 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