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

111
Views
TypeError: Cannot destructure property 'position' of 'undefined' as it is undefined

I am passing a function which changes states from Parent Component to Second Component and then Second Component to Third Component and calling from it.

This results in the following error:

TypeError: Cannot destructure property 'position' of 'undefined' as it is undefined

Following is my code for reference:

export class ParentComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      address: '',
      position: {
        lat: 0,
        lng: 0,
      },
    };
    this.locationChangeHandler = this.locationChangeHandler.bind(this);
  }

  locationChangeHandler({ position, address, places }) {
    // Set new location
    this.setState({ position, address });
  }

  render(){

<SecondComponent locationChangeHandler={this.locationChangeHandler}/>

}

Second Component:

<ThirdComponent locationChangeHandler={locationChangeHandler}/>

Third Component:

<FourthComponent onChange={locationChangeHandler()}/>

How do I resolve this? I am relatively new to ReactJs and would appreciate all help.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

can you change locationChangeHandler function like this

locationChangeHandler(loc) {
    // Set new location
        if(loc && loc.position && loc.address)
        this.setState({ position: loc.position, address: loc.address });
  }
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!