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

159
Views
can not use the child state that has been passed to parent React

i am new to React and i am working on a CV project. I have the following situation: PersonalData.js (child) that handles a form dynamically updating the state of the component. App.js(parent) contains the function eventHandler that is passed to PersonalData as a prop:

<Route path="/" exact element={<PersonalData onChange={this.eventHandler}/>} />

On the child side, i use the prop as it follows when i click the submit button:

  handleSubmit = (e) => {
    e.preventDefault();
    this.props.onChange(this.state)
  };

Returning to the parent component, the eventHandler looks like this:

  eventHandler = (data) =>{
    console.log(data.firstName)
    this.setState({
      firstName: data.firstName,
      lastName: data.lastName,
      age: data.age,
      location: data.location,
      email: data.email,
      phone: data.phone,
      gender: data.gender,
    })
    console.log(this.state);
  }

the first console.log shows the value, but after i update the state of the parent component, on the 2nd console.log the state is empty. Can't figure out what i am missing.

about 4 years ago · Juan Pablo Isaza
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!