Skip to content

Commit 81c0ba9

Browse files
committed
+memo
1 parent b8aa364 commit 81c0ba9

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

x-pack/plugins/lens/public/xy_visualization/xy_config_panel.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,27 @@ const ColorPicker = ({
188188
}
189189
};
190190

191-
const updateColorInState: EuiColorPickerProps['onChange'] = debounce((text, output) => {
192-
const newYConfigs = [...(layer.yConfig || [])];
193-
const existingIndex = newYConfigs.findIndex((yConfig) => yConfig.forAccessor === accessor);
194-
if (existingIndex !== -1) {
195-
if (text === '') {
196-
delete newYConfigs[existingIndex].color;
197-
} else {
198-
newYConfigs[existingIndex].color = output.hex;
199-
}
200-
} else {
201-
newYConfigs.push({
202-
forAccessor: accessor,
203-
color: output.hex,
204-
});
205-
}
206-
setState(updateLayer(state, { ...layer, yConfig: newYConfigs }, index));
207-
}, 256);
191+
const updateColorInState: EuiColorPickerProps['onChange'] = React.useMemo(
192+
() =>
193+
debounce((text, output) => {
194+
const newYConfigs = [...(layer.yConfig || [])];
195+
const existingIndex = newYConfigs.findIndex((yConfig) => yConfig.forAccessor === accessor);
196+
if (existingIndex !== -1) {
197+
if (text === '') {
198+
delete newYConfigs[existingIndex].color;
199+
} else {
200+
newYConfigs[existingIndex].color = output.hex;
201+
}
202+
} else {
203+
newYConfigs.push({
204+
forAccessor: accessor,
205+
color: output.hex,
206+
});
207+
}
208+
setState(updateLayer(state, { ...layer, yConfig: newYConfigs }, index));
209+
}, 256),
210+
[state, layer, accessor, index]
211+
);
208212

209213
return (
210214
<EuiToolTip

0 commit comments

Comments
 (0)