Created
June 16, 2021 08:46
-
-
Save ilxanlar/8eee52183d7f4095c5ef9c705f7e279c 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
import React, { useState, useEffect } from 'react' | |
function Example() { | |
const [width, setWidth] = useState(...) | |
useEffect(() => { | |
function handleResize(event) { | |
// Calculate window width... | |
setWidth(...) | |
} | |
window.addEventListener('resize', handleResize) | |
// Specify how to clean up after this effect: | |
return () => { | |
window.removeEventListener('resize', handleResize) | |
} | |
}) | |
return ( | |
<> | |
... | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment