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

106
Vistas
pass data between pages react

I have eventData which I need to pass from page A to B. Here's my code:

function eCE(eventData) {

    history.push({
      pathname: '/ece',
      state: eventData
   })

})

This function gets triggered on button click, so it passed eventData through to the function. Now I need to send eventData through to the next page, in which I would get to by calling /ece. However, I am trying to grab the state on the other page like so:

const { state } = this.props.location
console.log(state)

it isn't working, and the error I get is:

TypeError: undefined has no properties

not to sure what to do here. appreciate the help !

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

In page 1:

import { useHistory } from "react-router-dom";

function page1(){   
  const history = useHistory();

  const goToPage2 = () => {
    history.push("/page2", { age: 18 });
  }
  return <button onClick={goToPage2}>Go To Page2</button>
}

In page 2:

import { useLocation } from "react-router-dom";

function page2(){ 
  const location = useLocation();
  return <div><p>{location.state.age}</p></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