diff --git a/src/index.jsx b/src/index.jsx index da05722..5588408 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -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 = `