Skip to content

Commit

Permalink
Only recompute normalized filter when members list changes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertknight committed Nov 20, 2024
1 parent f139a60 commit 5e50668
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,21 @@ export default function EditGroupMembersForm({
};

const memberText = pluralize(members?.length ?? 0, 'member', 'members');
const normalizedFilter = filter.toLowerCase();

const filteredMembers = useMemo(() => {
if (!normalizedFilter || !members) {
if (!filter || !members) {
return members;
}

const normalizedFilter = filter.toLowerCase();

// nb. We can get away with lower-casing name and filter to do
// case-insensitive search because of the character set restrictions on
// usernames. This would be incorrect for Unicode text.
return members.filter(m =>
m.username.toLowerCase().includes(normalizedFilter),
);
}, [normalizedFilter, members]);
}, [filter, members]);

let emptyMessage;
if (members !== null && members.length > 0 && filter) {
Expand Down

0 comments on commit 5e50668

Please sign in to comment.