useWsInventories cleanup

This commit is contained in:
Keith Grant
2020-07-10 08:33:35 -07:00
parent f225df1acd
commit 38e0968690

View File

@@ -34,17 +34,13 @@ export default function useWsProjects(
const newInventories = await fetchInventoriesById( const newInventories = await fetchInventoriesById(
throttledInventoriesToFetch throttledInventoriesToFetch
); );
let updated = inventories; const updated = [...inventories];
newInventories.forEach(inventory => { newInventories.forEach(inventory => {
const index = inventories.findIndex(i => i.id === inventory.id); const index = inventories.findIndex(i => i.id === inventory.id);
if (index === -1) { if (index === -1) {
return; return;
} }
updated = [ updated[index] = inventory;
...updated.slice(0, index),
inventory,
...updated.slice(index + 1),
];
}); });
setInventories(updated); setInventories(updated);
})(); })();