Skip to content

Instantly share code, notes, and snippets.

@mushfiqweb
Created May 4, 2017 17:45
Show Gist options
  • Select an option

  • Save mushfiqweb/1cf970b1c169a534a97d81953c44b03c to your computer and use it in GitHub Desktop.

Select an option

Save mushfiqweb/1cf970b1c169a534a97d81953c44b03c to your computer and use it in GitHub Desktop.
class MyComponent extends React.Component {
// when the component is added to the DOM...
componentDidMount() {
window.addEventListener(‘resize’, this.onResizeHandler);
}
// when the component is removed from the DOM...
componentWillUnmount() {
window.removeEventListener(‘resize’, this.onResizeHandler);
}
onResizeHandler() {
console.log(‘The window has been resized!’);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment