Skip to content

Commit

Permalink
fix(hooks): resolve hydration issues by deferring state updates with …
Browse files Browse the repository at this point in the history
…startTransition in useResizing
  • Loading branch information
RabeeAbuBaker committed Oct 2, 2024
1 parent 397e782 commit 874d3ef
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ export function useResizing({ transitionDuration, disabled }: UseResizingInput)
useWindowEvent('resize', () => {
setResizing(true);
clearTimeout(resizingTimeout.current);
resizingTimeout.current = window.setTimeout(() => setResizing(false), 200);
resizingTimeout.current = window.setTimeout(
() =>
startTransition(() => {
setResizing(false);
}),
200
);
});

useIsomorphicEffect(() => {
startTransition(() => {
setResizing(true);
clearTimeout(disabledTimeout.current);
disabledTimeout.current = window.setTimeout(
() => setResizing(false),
transitionDuration || 0
);
});
setResizing(true);
clearTimeout(disabledTimeout.current);
disabledTimeout.current = window.setTimeout(
() =>
startTransition(() => {
setResizing(false);
}),
transitionDuration || 0
);
}, [disabled, transitionDuration]);

return resizing;
Expand Down

0 comments on commit 874d3ef

Please sign in to comment.