Everything You Need To Know About useEffect

PHOTO EMBED

Tue Jun 28 2022 13:11:17 GMT+0000 (Coordinated Universal Time)

Saved by @bushratv #jsx

function WindowSizeList({ url }) {
  const [windowWidth, setWindowWidth] = useState(window.innerWidth)
  const [items, setItems] = useState([])

  const updateWindowWidth = () => {
    setWindowWidth(window.innerWidth)
  }

  // TODO: Update list when url changes or on mount
  // TODO: Setup resize event listener on mount
  // TODO: Cleanup resize event listener on un-mount

  return (
    <>
      <div>Window Width: {windowWidth}</div>
      {items.map(item => {
        return <div key={item}>{item}</div>
      })}
    </>
  )
}
content_copyCOPY

https://blog.webdevsimplified.com/2020-04/use-effect/