We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
flushSync
1 parent e6bb382 commit 03d9f61Copy full SHA for 03d9f61
1 file changed
src/hooks/useGridDimensions.ts
@@ -1,4 +1,5 @@
1
import { useLayoutEffect, useRef, useState } from 'react';
2
+import { flushSync } from 'react-dom';
3
4
export function useGridDimensions() {
5
const gridRef = useRef<HTMLDivElement>(null);
@@ -27,9 +28,12 @@ export function useGridDimensions() {
27
28
const size = entries[0].contentBoxSize[0];
29
const { clientHeight, offsetHeight } = gridRef.current!;
30
- setInlineSize(size.inlineSize);
31
- setBlockSize(size.blockSize);
32
- setHorizontalScrollbarHeight(offsetHeight - clientHeight);
+ // we use flushSync here to avoid flashing scrollbars
+ flushSync(() => {
33
+ setInlineSize(size.inlineSize);
34
+ setBlockSize(size.blockSize);
35
+ setHorizontalScrollbarHeight(offsetHeight - clientHeight);
36
+ });
37
});
38
resizeObserver.observe(gridRef.current!);
39
0 commit comments