Skip to content

Instantly share code, notes, and snippets.

@ilxanlar
Created June 16, 2021 08:46
Show Gist options
  • Save ilxanlar/8eee52183d7f4095c5ef9c705f7e279c to your computer and use it in GitHub Desktop.
Save ilxanlar/8eee52183d7f4095c5ef9c705f7e279c to your computer and use it in GitHub Desktop.
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