🎃 Spookyberb 🎃 – 09-02 Nov 24

I need some help with the performance of a filter I made. It's taking 1.3s on updating a list of items. How could I improve this code to? I really have no idea.
useEffect(() => {
const newAccounts = Object.values(accountGroups).map((ownershipType) =>
ownershipType.map((group) => ({
...group,
accounts: group.accounts.map((account) => {
const isChecked = !!selectedFavoriteFilter.value;

return { ...account, expanded: [{ selected: isChecked && account.isFavorite }] };
}),
})),
);
const filteredFavoriteAccountGroups = {
single: newAccounts[0],
shared: newAccounts[1],
tutor: newAccounts[2],
proxy: newAccounts[3],
};

setAccountGroups(filteredFavoriteAccountGroups);
}, [selectedFavoriteFilter]);
useEffect(() => {
const newAccounts = Object.values(accountGroups).map((ownershipType) =>
ownershipType.map((group) => ({
...group,
accounts: group.accounts.map((account) => {
const isChecked = !!selectedFavoriteFilter.value;

return { ...account, expanded: [{ selected: isChecked && account.isFavorite }] };
}),
})),
);
const filteredFavoriteAccountGroups = {
single: newAccounts[0],
shared: newAccounts[1],
tutor: newAccounts[2],
proxy: newAccounts[3],
};

setAccountGroups(filteredFavoriteAccountGroups);
}, [selectedFavoriteFilter]);
I'm doing 3 loops to get to a deeply nested prop I have to add to each object in the list...
UU
Unknown User510d ago