Skip to content

Commit

Permalink
move var into function
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceharrison1984 committed Jan 11, 2023
1 parent cf4d9af commit 413c9b6
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/Schedulely/src/providers/BreakPointProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ export const BreakpointProvider = ({
containerRef: React.MutableRefObject<null>;
children: ReactNode;
}) => {
const breakpoints = { small: 500, large: 800 };
const [breakpoint, setBreakpoint] = useState<ComponentSize | undefined>();
const resizeObserver = useRef<ResizeObserver | undefined>();

const onResize: ResizeObserverCallback = useCallback(
(entries) => {
const { width } = entries[0].contentRect;
const onResize: ResizeObserverCallback = useCallback((entries) => {
const breakpoints = { small: 500, large: 800 };
const { width } = entries[0].contentRect;

if (width <= breakpoints.small) setBreakpoint('small');
if (width > breakpoints.small && width < breakpoints.large)
setBreakpoint('medium');
if (width >= breakpoints.large) setBreakpoint('large');
},
[breakpoints.large, breakpoints.small]
);
if (width <= breakpoints.small) setBreakpoint('small');
if (width > breakpoints.small && width < breakpoints.large)
setBreakpoint('medium');
if (width >= breakpoints.large) setBreakpoint('large');
}, []);

useEffect(() => {
resizeObserver.current = new ResizeObserver(onResize);
Expand Down

0 comments on commit 413c9b6

Please sign in to comment.