Closed fazakasc closed 5 years ago
@fazakasc fixed 285679291de6ffc285c5ca3435f07e09b4d6d923
With this fix, the timer goes until -0 and only after that is triggered the onFinish. You should not have changed the if(until <= 1) to if(until <= 0), just as suggested before, move the setState({until:0} right after the clearInterval(this.timer).
@fazakasc Okay thanks It's now fixed on ba36802a12a44f96a6b3cf969543c35e42112f3d react-native-countdown-component@1.8.2
Thanks. It works perfectly now.
react-native-countdown-component@2.2.0 still show warning :
Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application.
.
my warning is solved with these :
updateTimer = () => {
...
if (until === 1 || (until === 0 && lastUntil !== 1)) {
if (this.props.onFinish) {
this.props.onFinish();
} // move this if (this.props.onFinish)
if (this.props.onChange) {
this.props.onChange();
}
}
...
};
.
change to :
updateTimer = () => {
...
if (until === 1 || (until === 0 && lastUntil !== 1)) {
// updated
if (this.props.onChange) {
this.props.onChange();
}
}
if (until === 0) {
this.setState({lastUntil: 0, until: 0});
if (this.props.onFinish) {
this.props.onFinish();
} // move here
...
};
react-native-countdown-component@2.2.0 still show warning : Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. . my warning is solved with these : updateTimer = () => { ... if (until === 1 || (until === 0 && lastUntil !== 1)) { if (this.props.onFinish) { this.props.onFinish(); } // move this if (this.props.onFinish) if (this.props.onChange) { this.props.onChange(); } } ... }; . change to : updateTimer = () => { ... if (until === 1 || (until === 0 && lastUntil !== 1)) { // updated if (this.props.onChange) { this.props.onChange(); } }
if (until === 0) { this.setState({lastUntil: 0, until: 0}); if (this.props.onFinish) { this.props.onFinish(); } // move here ...
};
same issue still there. and it solved by this. thanks.
and update to 2.5.0 it solved the problem too.
When onFinish is defined, this warning is issued: "Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application". This happens if in the custom onFinish method for instance the user navigates to other screen, but the next line is this.setState({until: 0}); which is triggered toward an unmounted component already. What I suggest is to move the this.setState({until: 0}); right after the if (until <= 1) and before the clearInterval(this.timer) in the updateTimer method.