Skip to content

Commit

Permalink
fix: DH-17861: Fix the warning about IrisGridModelUpdater render not …
Browse files Browse the repository at this point in the history
…being a pure function (#2249)

`pendingRowCount` and `pendingDataMap` setters in `IrisGridModelUpdater`
were emitting an event in the render cycle, that caused a React warning
about the render not being a pure function because the event triggered
state update in `IrisGrid`.
Wrap the setters in `useEffect` instead of `useOnChange` so the events
are emitted after the render.
  • Loading branch information
vbabich authored Oct 4, 2024
1 parent 5e116d8 commit 9e83393
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/iris-grid/src/IrisGridModelUpdater.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/require-default-props */
/* eslint-disable no-param-reassign */
import { useMemo } from 'react';
import { useEffect, useMemo } from 'react';
import type { dh } from '@deephaven/jsapi-types';
import { type ModelIndex, type MoveOperation } from '@deephaven/grid';
import {
Expand Down Expand Up @@ -176,18 +176,6 @@ function IrisGridModelUpdater({
},
[model, isTotalsAvailable, totalsConfig]
);
useOnChange(
function updatePendingRowCount() {
model.pendingRowCount = pendingRowCount;
},
[model, pendingRowCount]
);
useOnChange(
function updatePendingDataMap() {
model.pendingDataMap = pendingDataMap;
},
[model, pendingDataMap]
);
useOnChange(
function updateFrozenColumns() {
if (frozenColumns) {
Expand All @@ -210,6 +198,20 @@ function IrisGridModelUpdater({
},
[model, partitionConfig]
);
// These setters are wrapped in useEffect instead of useOnChange because they emit an event
// that potentially causes side effects, violating the rule that render should be a pure function.
useEffect(
function updatePendingRowCount() {
model.pendingRowCount = pendingRowCount;
},
[model, pendingRowCount]
);
useEffect(
function updatePendingDataMap() {
model.pendingDataMap = pendingDataMap;
},
[model, pendingDataMap]
);

return null;
}
Expand Down

0 comments on commit 9e83393

Please sign in to comment.