Rewrite frontend using create-react-app
This commit is contained in:
32
client/WindowSize.js
Normal file
32
client/WindowSize.js
Normal file
@ -0,0 +1,32 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import { addEvent, removeEvent } from './DOMUtils'
|
||||
|
||||
const ResizeEvent = 'resize'
|
||||
|
||||
class WindowSize extends React.Component {
|
||||
static propTypes = {
|
||||
onChange: PropTypes.func
|
||||
}
|
||||
|
||||
handleWindowResize = () => {
|
||||
if (this.props.onChange)
|
||||
this.props.onChange({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
})
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
addEvent(window, ResizeEvent, this.handleWindowResize)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
removeEvent(window, ResizeEvent, this.handleWindowResize)
|
||||
}
|
||||
|
||||
render() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default WindowSize
|
Reference in New Issue
Block a user