fix: useComponentSize should run in useLayoutEffect

This commit is contained in:
Tom Moor
2025-02-05 22:39:10 -05:00
parent 676e89a58e
commit ce51fa9957

View File

@@ -1,4 +1,4 @@
import { useState, useLayoutEffect, useEffect } from "react";
import { useState, useLayoutEffect } from "react";
const defaultRect = {
top: 0,
@@ -33,7 +33,7 @@ export function useComponentSize(
return () => sizeObserver.disconnect();
}, [element]);
useEffect(() => {
useLayoutEffect(() => {
const handleResize = () => {
setSize((state) => {
const rect = element?.getBoundingClientRect();