Skip to content

Commit fd0a4b9

Browse files
chore: remove other calls to requestAnimationFrame
1 parent 527d27b commit fd0a4b9

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const useDimensions = <T extends HTMLElement | null>({
107107
// eslint-disable-next-line compat/compat
108108
observerRef.current = new (polyfill || window.ResizeObserver)(
109109
([entry]: any) => {
110-
window.requestAnimationFrame(() => {
110+
rafId = window.requestAnimationFrame(() => {
111111
const { contentBoxSize, borderBoxSize, contentRect } = entry;
112112

113113
let boxSize = contentBoxSize;
@@ -166,25 +166,21 @@ const useDimensions = <T extends HTMLElement | null>({
166166
breakpoints &&
167167
updateOnBreakpointChange
168168
) {
169-
rafId = requestAnimationFrame(() => {
170-
setState((prev) =>
171-
prev.currentBreakpoint !== next.currentBreakpoint ? next : prev
172-
);
173-
});
169+
setState((prev) =>
170+
prev.currentBreakpoint !== next.currentBreakpoint ? next : prev
171+
);
174172
return;
175173
}
176174

177-
rafId = requestAnimationFrame(() => {
178-
setState(next);
179-
});
175+
setState(next);
180176
})
181177
});
182178

183179
observe();
184180

185181
return () => {
186182
unobserve();
187-
if (rafId) cancelAnimationFrame(rafId);
183+
if (rafId) window.cancelAnimationFrame(rafId);
188184
};
189185
// eslint-disable-next-line react-hooks/exhaustive-deps
190186
}, [

0 commit comments

Comments
 (0)