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

268
Visualizações
Can't call setState on a component that is not yet mounted - react native

Keep getting the following error message in React Native, really don't understand where it is coming from

Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to this.state directly or define a state = {}; class property with the desired state in the ConnectionMqtt component.

constructor(){
    super();
    this.onMessageArrived = this.onMessageArrived.bind(this)
}

componentDidMount() {
    const conn = new ConnectionMqtt();
    conn.onMessageArrived = this.onMessageArrived;
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should not use setState in the constructor since the component is not mounted yet. In this case clickMe() method calls setState(). Instead, initialize the state directly. Like,

constructor(props) {
    super(props);
    // Don't call this.setState() here!
    this.state = { counter: 0 };
    this.handleClick = this.handleClick.bind(this);
}

example if from https://reactjs.org/docs/react-component.html#constructor

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