Created
December 22, 2018 08:00
-
-
Save mDibyo/1d994fb8e3288aafe7bf5bf2e2d7892a to your computer and use it in GitHub Desktop.
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
class WindowInfo extends React.PureComponent { | |
render() { | |
const WithWindowWidth = withHook(() => { | |
const [width, setWidth] = useState(window.innerWidth); | |
const handleWindowResize = () => setWidth(window.innerWidth); | |
useEffect(() => { | |
window.addEventListener('resize', handleWindowResize); | |
return () => window.removeEventListener('resize', handleWindowResize); | |
}); | |
return width; | |
}); | |
return ( | |
<WithWindowWidth> | |
{width => <div>The window width is {width}</div>} | |
</WithWindowWidth> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment