Created
December 13, 2015 13:30
-
-
Save MicheleBertoli/75de5da8fd625b51c03c to your computer and use it in GitHub Desktop.
Memory Leak
This file contains 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 characters
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