• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

130
Vistas
useNavigate hook not working in React router

I have two pages, Dashboard and Quiz. Dashboard triggers an event which calls the useNavigate function with the state.

const nav = useNavigate();
const goToTest = (e)=>{

    e.preventDefault()

    nav('/student/Quiz',{state:{id:1}});
  }

In quiz, I then use useLocation to try and get the data but it doesn't seem to work.

function Quiz() {
  const {data} = useLocation();
  console.log(data);

If i don't destructure data in quiz, it shows some json data, but state is always null

hash: ""
key: "(a key was here)"
pathname: "/student/Quiz" (Dashboard and quiz are both in the same directory as student)
search: ""
state: null
almost 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Turns out it was a version issue. This happened on 6.14 but when I updated it to 6.2 it works fine.

The docs had mentioned v6 and above, so I thought I was in the clear.

I'll leave this question up for anyone who gets the same issue.

almost 3 years ago · Santiago Trujillo 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda