Skip to content

Commit 040610b

Browse files
committed
refactor: useWidgetRowHeight
1 parent dec8c51 commit 040610b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

frontend/src/app/hooks/useWidgetRowHeight.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,22 @@ import {
2121
BASE_VIEW_WIDTH,
2222
MIN_ROW_HEIGHT,
2323
} from 'app/pages/DashBoardPage/constants';
24-
import { useMemo } from 'react';
24+
import { useEffect, useMemo, useState } from 'react';
2525
import useResizeObserver from './useResizeObserver';
2626

2727
export const useWidgetRowHeight = () => {
28+
const [cacheW, setCacheW] = useState(0);
2829
const { ref, width = 0 } = useResizeObserver<HTMLDivElement>();
30+
31+
useEffect(() => {
32+
if (width > 0) {
33+
setCacheW(width);
34+
}
35+
}, [width]);
2936
const widgetRowHeight = useMemo(() => {
30-
let dynamicHeight = (width * BASE_ROW_HEIGHT) / BASE_VIEW_WIDTH;
37+
let dynamicHeight = (cacheW * BASE_ROW_HEIGHT) / BASE_VIEW_WIDTH;
3138
return Math.max(dynamicHeight, MIN_ROW_HEIGHT);
32-
}, [width]);
39+
}, [cacheW]);
3340
return {
3441
ref,
3542
widgetRowHeight,

0 commit comments

Comments
 (0)