Finally, I have found the proper way to do it with react. Please note that it does not concern ag-grid but it only react rendeting mechanism.
const addItem = useCallback((item: any) => {
const exist = selectedItems.findIndex(
(existingItem) => existingItem.name === item.name
);
if (exist === -1) {
setSelectedItems((items) => items.concat(item));
}
}, []);
const addItem = useCallback((item: any) => {
setSelectedItems((items) => {
const exist = items.findIndex(
(existingItem) => existingItem.name === item.name
);
if (exist === -1) {
return items.concat(item);
}
return items;
});
}, []);
Codesandbox updated