Skip to content

Commit

Permalink
Fix significant memory leak
Browse files Browse the repository at this point in the history
This checks to make sure props change before reinitializing icons
ajhenry committed Jul 9, 2019
1 parent f235fcc commit bb90163
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ReactAnimatedWeather.js
Original file line number Diff line number Diff line change
@@ -17,6 +17,14 @@ class ReactAnimatedWeather extends React.Component {
}

componentWillReceiveProps(nextProps) {
// If color props match, don't reinitialize the icon
if (this.skyconIcon.color === nextProps.color) {
return;
}

// Remove the old icon
this.skyconIcon.remove(this.skycon);

this.skyconIcon = new Skycons({
color: nextProps.color
});
@@ -37,7 +45,9 @@ class ReactAnimatedWeather extends React.Component {
const { size } = this.props;
return (
<canvas
ref={(canvas) => { this.skycon = canvas; }}
ref={canvas => {
this.skycon = canvas;
}}
width={size}
height={size}
/>

0 comments on commit bb90163

Please sign in to comment.