Skip to content

Commit

Permalink
fix: code rabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Jan 7, 2025
1 parent eca6e60 commit f98e517
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions hooks/useResponsivePageSize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { debounce } from '@/helpers';
import { useState, useCallback, useEffect } from 'react';
import { useState, useCallback, useEffect, useMemo } from 'react';

interface PageSizeConfig {
[key: string]: number;
Expand Down Expand Up @@ -31,18 +31,18 @@ export function useResponsivePageSize<T extends PageSizeConfig>(
findMatchingConfig(getWindowDimensions(), sizeLookup, defaultSizes)
);

const updatePageSizes = useCallback(() => {
return debounce(() => {
setPageSize(findMatchingConfig(getWindowDimensions(), sizeLookup, defaultSizes));
}, 150);
}, [sizeLookup, defaultSizes]);

const debouncedResizeHandler = useMemo(
() =>
debounce(() => {
setPageSize(findMatchingConfig(getWindowDimensions(), sizeLookup, defaultSizes));
}, 150),
[sizeLookup, defaultSizes]
);
useEffect(() => {
const handleResize = updatePageSizes();
handleResize();
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, [updatePageSizes]);
debouncedResizeHandler();
window.addEventListener('resize', debouncedResizeHandler);
return () => window.removeEventListener('resize', debouncedResizeHandler);
}, [debouncedResizeHandler]);

return pageSize;
}

0 comments on commit f98e517

Please sign in to comment.