Skip to content

Commit

Permalink
Fixes rerender.
Browse files Browse the repository at this point in the history
  • Loading branch information
natalyjazzviolin committed Feb 10, 2025
1 parent 905a2ef commit 8ffc18d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
12 changes: 7 additions & 5 deletions src/components/Grid/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const Cell = memo(
rowHeight,
rowStart,
rowAutoHeight,
updateRowHeight,
} = data;

const currentRowIndex = rowIndex + rowStart;
Expand Down Expand Up @@ -58,16 +59,17 @@ export const Cell = memo(
const cellRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (cellRef.current && data.updateRowHeight) {
if (rowCount !== 1) return;
else if (cellRef.current) {
const height = cellRef.current.getBoundingClientRect().height;
data.updateRowHeight(rowIndex, height);
updateRowHeight(rowIndex, height);
}
});
}, [rowCount, updateRowHeight, rowIndex]);

const styleWithHeight = {
...style,
height: "auto"
}
height: "auto",
};

return (
<div
Expand Down
21 changes: 13 additions & 8 deletions src/components/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,20 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
[rowHeight, rowAutoHeight]
);

const updateRowHeight = useCallback((rowIndex: number, height: number) => {
const prevHeight = rowHeightsRef.current.get(rowIndex) ?? 0;
if (height > prevHeight) {
rowHeightsRef.current.set(rowIndex, height);
if (gridRef.current) {
gridRef.current.resetAfterRowIndex(rowIndex);
const updateRowHeight = useCallback(
(rowIndex: number, height: number) => {
if (rowCount !== 1) return;

const prevHeight = rowHeightsRef.current.get(rowIndex) ?? 0;
if (height > prevHeight) {
rowHeightsRef.current.set(rowIndex, height);
if (gridRef.current) {
gridRef.current.resetAfterRowIndex(rowIndex);
}
}
}
}, []);
},
[rowCount]
);

const customOnCopy: () => Promise<void> = useMemo(() => {
const result = async () => {
Expand Down

0 comments on commit 8ffc18d

Please sign in to comment.