index.js 882 Bytes
Newer Older
zhanghaozhe committed
1
import React, { PureComponent } from 'react';
zhanghaozhe committed
2

xuzhenghua committed
3 4 5 6 7 8 9
function setSize() {
    document.body.style.height = `${window.innerHeight}px`
    document.getElementById('root').style.height = `${window.innerHeight}px`
    document.documentElement.style.height = `${window.innerHeight}px`

}

zhanghaozhe committed
10
export default function (WrappedComponent) {
zhanghaozhe committed
11
    return class extends PureComponent {
zhanghaozhe committed
12
        componentDidMount() {
xuzhenghua committed
13 14
            setSize()
            window.addEventListener('resize', setSize)
zhanghaozhe committed
15 16 17 18
        }
        componentWillUnmount() {
            document.body.style.height = `auto`
            document.getElementById('root').style.height = `auto`
zhanghaozhe committed
19
            document.documentElement.style.height = 'auto'
xuzhenghua committed
20
            window.removeEventListener('resize', setSize)
zhanghaozhe committed
21 22 23 24 25 26 27 28 29 30
        }

        render() {
            return (
                <WrappedComponent {...this.props}/>
            );
        }
    }
}