Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda