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

100
Views
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 answers
Answer question

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 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!