fix useWindowSize

This commit is contained in:
Asad Umar 2022-02-04 21:25:00 +05:00 committed by Thomas Zarebczan
parent 00c9410253
commit e45ef63d41

View file

@ -3,7 +3,8 @@ import React from 'react';
export function useWindowSize(fn) {
const isWindowClient = typeof window === 'object';
const [windowSize, setWindowSize] = React.useState(isWindowClient ? window.innerWidth : undefined);
const initialState = fn ? fn(window.innerWidth) : window.innerWidth;
const [windowSize, setWindowSize] = React.useState(isWindowClient ? initialState : undefined);
React.useEffect(() => {
function setSize() {