R
Reactiflux

πŸŽƒ Spookyberb πŸŽƒ – 09-02 Nov 24

πŸŽƒ Spookyberb πŸŽƒ – 09-02 Nov 24

Sβ›„Snowberbβ›„11/24/2022
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...
UUUnknown User11/25/2022
2 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

πŸŽƒ Spookyberb πŸŽƒ – 09-02 Nov 24

Join Server