react-native-counter icon indicating copy to clipboard operation
react-native-counter copied to clipboard

setState is called on unmounted component

Open amed opened this issue 8 years ago • 7 comments

react-native-counter used for creating a counter in home page that start from 0 and counts the levels that the user reached.

<Counter
  end={this.props.level}
  start={0}
  time={2000}
  easing='linear' />

versions:

"react": "~15.4.0-rc.4",
"react-native": "0.40.0",
"react-native-counter": "^0.1.1",

screen shot 2017-03-30 at 11 55 09 In both IOS and Android this warning is occurred.

amed avatar Mar 30 '17 10:03 amed

Can you show me what's your code for your Home page?

Kerumen avatar Mar 30 '17 10:03 Kerumen

It is a fat js file. After debugging, it turns out that the home screen do reRendering a child component which has <Counter />

amed avatar Mar 31 '17 08:03 amed

which has? 🤔

Kerumen avatar Jul 05 '17 17:07 Kerumen

It this still an issue?

Kerumen avatar Jul 06 '17 08:07 Kerumen

We had to ignore it, throughout console.ignoredYellowBox = ['Warning: setStat(...):'] We could not prevent the parent homeView from re-rendering several times.

amed avatar Jul 06 '17 12:07 amed

Just faced this problem too. And i found out that the requestAnimationFrame is not cancelled during component unmount.

The warning should be fixed by the following code changes: (For ES5, react-native-timer-mixin should solve the problem)

  componentDidMount() {
    this.startTime = Date.now();
    this.frameAnimationRequest = requestAnimationFrame(this.animate.bind(this));
  }
  componentWillUnmount() {
    cancelAnimationFrame(this.frameAnimationRequest);
  }
  animate() {
    const { onComplete } = this.props;

    if (this.stop) {
      if (onComplete) onComplete();
      return;
    }

    this.frameAnimationRequest = requestAnimationFrame(this.animate.bind(this));
    this.draw();
  }

Hope this help !

tikkichan4 avatar Jul 31 '17 09:07 tikkichan4

Can you submit a PR? Would be happy to merge it!

Kerumen avatar Jul 31 '17 09:07 Kerumen