Skip to content

Instantly share code, notes, and snippets.

@alejovdev
Created May 21, 2020 16:53
Show Gist options
  • Save alejovdev/e99e9eac1af92aad3bfe08b4222e15b7 to your computer and use it in GitHub Desktop.
Save alejovdev/e99e9eac1af92aad3bfe08b4222e15b7 to your computer and use it in GitHub Desktop.
import React, { useState, useLayoutEffect, useRef } from 'react'
function MyComponent() {
const [windowSize, _setWindowSize] = useState([0, 0])
const windowSizeRef = useRef(windowSize)
const setWindowSize = (value) => {
windowSizeRef.current = value
_setWindowSize(value)
}
// Here we can normally use setWindowSize([x,y]) and windowSize
useLayoutEffect(() => {
function onWindowResize() {}
return () => {}
}, [])
return <div>Hi There</div>
}
export default MyComponent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment