Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
24 replies
Thund3rD3v

Help needed handling 1k react checkboxes

if I have a state of arrays that has all the selected users id and I have 1000 users and when a user is selected there is lag how would I handle that my current handleUserSelected code:
function handleUserSelected(value: string) {
    const currentIndex = selectedUsers.indexOf(value);
    const newSelected = [...selectedUsers];

    if (currentIndex === -1) {
      newSelected.push(value);
    } else {
      newSelected.splice(currentIndex, 1);
    }

    setSelectedUsers(newSelected);
  }
Was this page helpful?