score:0

Accepted answer

my thought is calling new car() just call the constructor and not the render method, which means the component does not start mounting (see lifecycle document https://facebook.github.io/react/docs/component-specs.html). so the warning means "hey, your component did not start mounting, how come you want to setstate, it has something wrong".

if you are ok with using testutils, you can have something like

var car = testutils.renderintodocument(
   <car />
);

score:0

first of all problem looks like to be more specific to your component, so without posting at least your render method not much can be said.

otherwise a quick fix would be to check whether your component is mounted or not, like this:

componentwillunmount() {
   this.isunmounted = true;
}

setcolor(color) {
   if (!this.isunmounted) {
      this.setstate({ color : color });
   }
}

other solution can be to use try catch:

setcolor(color) {
   try {
    this.setstate({ color : color });
    return true;
  } catch (e) {
    return false;
  }
}

Related Query

More Query from same tag