- 
      
- 
        Save akinsho/c210f87bb08eb6a6f895e8ca5eb0b8fe to your computer and use it in GitHub Desktop. 
Revisions
- 
        jacob-beltran revised this gist Mar 6, 2017 . No changes.There are no files selected for viewing
- 
        jacob-beltran revised this gist Mar 6, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ startLoop() { } loop() { // perform loop work here this.theoreticalComponentAnimationFunction() // Set up next iteration of the loop 
- 
        jacob-beltran revised this gist Mar 6, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,7 @@ startLoop() { loop() { /* perform loop work here */ this.theoreticalComponentAnimationFunction() // Set up next iteration of the loop this.frameId = window.requestAnimationFrame( this.loop ) 
- 
        jacob-beltran revised this gist Mar 6, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,8 +15,9 @@ startLoop() { } loop() { /* perform loop work here */ // Set up next iteration of the loop this.frameId = window.requestAnimationFrame( this.loop ) } 
- 
        jacob-beltran created this gist Mar 6, 2017 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ // How to ensure that our animation loop ends on component unount componentDidMount() { this.startLoop(); } componentWillUnmount() { this.stopLoop(); } startLoop() { if( !this._frameId ) { this._frameId = window.requestAnimationFrame( this.loop ); } } loop() { // perform loop work here this.frameId = window.requestAnimationFrame( this.loop ) } stopLoop() { window.cancelAnimationFrame( this._frameId ); // Note: no need to worry if the loop has already been cancelled // cancelAnimationFrame() won't throw an error }