Merge pull request #2 from lokiuz/master

Fixes #1 - If the component is mounted and then unmounted immediately, its possible for the timeout to fire after unmounting leading React throwing a warning.
This commit is contained in:
Kevin Qi 2016-11-08 11:26:06 -05:00 committed by GitHub
commit 7026b2c8fb

View File

@ -11,8 +11,8 @@ class CircularProgressbar extends React.Component {
componentDidMount() {
if (this.props.initialAnimation) {
setTimeout(() => {
window.requestAnimationFrame(() => {
this.initialTimeout = setTimeout(() => {
this.requestAnimationFrame = window.requestAnimationFrame(() => {
this.setState({
percentage: this.props.percentage,
});
@ -27,6 +27,11 @@ class CircularProgressbar extends React.Component {
});
}
componentWillUnmount() {
clearTimeout(this.initialTimeout);
window.cancelAnimationFrame(this.requestAnimationFrame);
}
render() {
const radius = (50 - this.props.strokeWidth / 2);
const pathDescription = `