Skip to content

Commit b7d9a7e

Browse files
committed
fix: set tableStyle only once
1 parent 744752f commit b7d9a7e

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

src/containers/Storage/PaginatedStorageNodes.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,20 @@ function StorageNodesComponent({
8080
viewContext,
8181
});
8282

83-
const [tableStyle, setTableStyle] = React.useState<React.CSSProperties>({});
84-
85-
const handleDataFetched = React.useCallback((data: any) => {
86-
if (data?.columnSettings) {
87-
const {maxSlotsPerDisk, maxDisksPerNode} = data.columnSettings;
88-
setTableStyle({
89-
[MAX_SLOTS_CSS_VAR]: maxSlotsPerDisk,
90-
[MAX_DISKS_CSS_VAR]: maxDisksPerNode,
91-
} as React.CSSProperties);
92-
}
93-
}, []);
83+
const [tableStyle, setTableStyle] = React.useState<React.CSSProperties | undefined>(undefined);
84+
85+
const handleDataFetched = React.useCallback(
86+
(data: PaginatedTableData<PreparedStorageNode>) => {
87+
if (data?.columnSettings && !tableStyle) {
88+
const {maxSlotsPerDisk, maxDisksPerNode} = data.columnSettings;
89+
setTableStyle({
90+
[MAX_SLOTS_CSS_VAR]: maxSlotsPerDisk,
91+
[MAX_DISKS_CSS_VAR]: maxDisksPerNode,
92+
} as React.CSSProperties);
93+
}
94+
},
95+
[tableStyle],
96+
);
9497

9598
const renderControls: RenderControls = ({totalEntities, foundEntities, inited}) => {
9699
return (
@@ -249,17 +252,20 @@ function StorageNodesTableGroupContent({
249252
columns,
250253
initialEntitiesCount,
251254
}: StorageNodesTableGroupContentProps) {
252-
const [tableStyle, setTableStyle] = React.useState<React.CSSProperties>({});
253-
254-
const handleDataFetched = React.useCallback((data: PaginatedTableData<PreparedStorageNode>) => {
255-
if (data?.columnSettings) {
256-
const {maxSlotsPerDisk, maxDisksPerNode} = data.columnSettings;
257-
setTableStyle({
258-
[MAX_SLOTS_CSS_VAR]: maxSlotsPerDisk,
259-
[MAX_DISKS_CSS_VAR]: maxDisksPerNode,
260-
} as React.CSSProperties);
261-
}
262-
}, []);
255+
const [tableStyle, setTableStyle] = React.useState<React.CSSProperties | undefined>(undefined);
256+
257+
const handleDataFetched = React.useCallback(
258+
(data: PaginatedTableData<PreparedStorageNode>) => {
259+
if (data?.columnSettings && !tableStyle) {
260+
const {maxSlotsPerDisk, maxDisksPerNode} = data.columnSettings;
261+
setTableStyle({
262+
[MAX_SLOTS_CSS_VAR]: maxSlotsPerDisk,
263+
[MAX_DISKS_CSS_VAR]: maxDisksPerNode,
264+
} as React.CSSProperties);
265+
}
266+
},
267+
[tableStyle],
268+
);
263269

264270
return (
265271
<PaginatedStorageNodesTable

0 commit comments

Comments
 (0)