Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const useSizeHook = (dim, initialValue, opt) => {
const {fps, leading} = opt
const [size, setThrottledSize] = useThrottle(
typeof document === 'undefined'
? initialValue
: document.documentElement[dim],
fps,
leading
)
useEffect(() => {
const setSize = () => setThrottledSize(document.documentElement[dim])
window.addEventListener('resize', setSize)
window.addEventListener('orientationchange', setSize)
return () => {
window.removeEventListener('resize', setSize)
window.removeEventListener('orientationchange', setSize)
}
const useSizeHook = (
dim: Dimension,
initialValue?: number,
options: ThrottleOptions = emptyObj
): number => {
const {fps, leading} = options
const [size, setThrottledSize] = useThrottle(
typeof document === 'undefined'
? initialValue
: document.documentElement[dim],
fps,
leading
)
useEffect(() => {
const setSize = (): void => setThrottledSize(document.documentElement[dim])
window.addEventListener('resize', setSize)
window.addEventListener('orientationchange', setSize)
return (): void => {
window.removeEventListener('resize', setSize)
window.removeEventListener('orientationchange', setSize)
}