Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created December 13, 2015 13:30
Show Gist options
  • Save MicheleBertoli/75de5da8fd625b51c03c to your computer and use it in GitHub Desktop.
Save MicheleBertoli/75de5da8fd625b51c03c to your computer and use it in GitHub Desktop.
Memory Leak
import React from 'react';
import ReactDOM from 'react-dom';
import {Gmaps} from 'react-gmaps';
let interval;
const App = React.createClass({
getInitialState() {
return {
count: 0
};
},
handleStart() {
interval = setInterval(() => {
this.setState({
count: this.state.count + 1
});
}, 100);
},
handleStop() {
clearInterval(interval);
},
render() {
return (
<div>
<button onClick={this.handleStop}>
Stop
</button>
<button onClick={this.handleStart}>
Start
</button>
<div>{this.state.count}</div>
{interval &&
<Gmaps
key={this.state.count}
width="200px"
height="200px"
lat={-34.397}
lng={150.644}
zoom={8} />
}
</div>
);
}
});
ReactDOM.render(<App />, document.getElementById('gmaps'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment