Fix/use has window width changed enough (#894)
* fix render of toggle. * Fix useHasWindowWidthChangedEnough * fix flow Co-authored-by: Asad Umar <au@visuary.fr>
This commit is contained in:
parent
b3c4ce05fa
commit
50423111af
1 changed files with 4 additions and 4 deletions
|
@ -24,14 +24,14 @@ export function useWindowSize() {
|
|||
|
||||
function useHasWindowWidthChangedEnough(comparisonFn: (windowSize: number) => boolean) {
|
||||
const isWindowClient = typeof window === 'object';
|
||||
const initialState = isWindowClient ? comparisonFn(window.innerWidth) : comparisonFn(DEFAULT_SCREEN_SIZE);
|
||||
const [windowSize, setWindowSize] = React.useState(initialState);
|
||||
const prev = useRef(window.innerWidth);
|
||||
const initialState: boolean = isWindowClient ? comparisonFn(window.innerWidth) : comparisonFn(DEFAULT_SCREEN_SIZE);
|
||||
const [windowSize, setWindowSize] = React.useState<boolean>(initialState);
|
||||
const prev = useRef<boolean>(initialState);
|
||||
|
||||
React.useEffect(() => {
|
||||
function setSize() {
|
||||
const curr = comparisonFn(window.innerWidth);
|
||||
if (prev !== curr) {
|
||||
if (prev.current !== curr) {
|
||||
setWindowSize(curr);
|
||||
prev.current = curr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue