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

266
Views
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 answers
Answer question

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 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!