Skip to content

Commit 643955f

Browse files
authored
fix: cell variants memo (#1105)
1 parent fc7c60c commit 643955f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

public/r/data-grid.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/components/data-grid/data-grid-cell-variants.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,10 @@ export function SelectCell<TData>({
873873
const [value, setValue] = React.useState(initialValue);
874874
const containerRef = React.useRef<HTMLDivElement>(null);
875875
const cellOpts = cell.column.columnDef.meta?.cell;
876-
const options = cellOpts?.variant === "select" ? cellOpts.options : [];
876+
const options = React.useMemo(
877+
() => (cellOpts?.variant === "select" ? cellOpts.options : []),
878+
[cellOpts],
879+
);
877880
const optionByValue = React.useMemo(
878881
() => new Map(options.map((option) => [option.value, option])),
879882
[options],
@@ -1017,7 +1020,10 @@ export function MultiSelectCell<TData>({
10171020
const containerRef = React.useRef<HTMLDivElement>(null);
10181021
const inputRef = React.useRef<HTMLInputElement>(null);
10191022
const cellOpts = cell.column.columnDef.meta?.cell;
1020-
const options = cellOpts?.variant === "multi-select" ? cellOpts.options : [];
1023+
const options = React.useMemo(
1024+
() => (cellOpts?.variant === "multi-select" ? cellOpts.options : []),
1025+
[cellOpts],
1026+
);
10211027
const optionByValue = React.useMemo(
10221028
() => new Map(options.map((option) => [option.value, option])),
10231029
[options],

0 commit comments

Comments
 (0)