Sniberb
Sniberbβ€’3y ago

πŸŽƒ 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...
2 Replies
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
reactibot
reactibotβ€’3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1045263137961685032