Skip to content

Instantly share code, notes, and snippets.

@jordaaash
Created August 26, 2015 19:17
Show Gist options
  • Save jordaaash/4216415649aab40d7628 to your computer and use it in GitHub Desktop.
Save jordaaash/4216415649aab40d7628 to your computer and use it in GitHub Desktop.
Resize mixin for responsive components
'use strict';
var ResizeMixin, raf;
if (typeof window === 'undefined') {
ResizeMixin = {};
}
else {
raf = require('raf');
ResizeMixin = {
componentDidMount () {
window.addEventListener('resize', this._handleResize, false);
},
componentWillUnmount () {
window.removeEventListener('resize', this._handleResize, false);
},
_handleResize (event) {
raf((function () {
if (this.isMounted()) {
this.handleResize(event);
}
}).bind(this));
}
};
}
module.exports = ResizeMixin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment