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

250
Visualizações
Unhandled Rejection (TypeError): can't access property "country", this.props is undefined

i'm working on a react app

when run this function by infinite scroll i'll get error

Unhandled Rejection (TypeError): can't access property "country", this.props is undefined

async pageUpdater() {
  let url = `https://newsapi.org/v2/top-headlines?country=${this.props.country}&category=${this.props.category}&apiKey=myapi&page=${this.state.page}&pageSize=${this.props.pageSize}`;
  this.setState({ loading: true })
  await fetch(url).then(response => response.json()).then(data => {
    this.setState({ articles: data.articles, totalResults: data.totalResults, loading: false })
  })
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have to use the arrow function or need to bind the this with this function.

The JavaScript has the function scope and the this pointer is changed on the function scope.

For example-

const pageUpdater = async () => {
 // your code here
}

or

You also could bind the this with the function at the component connstructor.

constructor() {
  this.pageUpdater = this.pageUpdater.bind(this);
}

For more about this read https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

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