Goal: Allow the user to select items in a list


Goal: Allow the user to select items in a list.

Three state approaches, from worst, to best:

1. list and selectedList 👎
2. list and selectedIds 👎
3. list with a selected property 👍

Principle: Store related data in one array. This simplifies and avoids out-of-sync bugs.

I should have added a 4th option: Store the selected ids in an "map" object.

// User's with id 1 and 2 are selected
const selectedUserIds = {
1: true,
2: true
};

This is a fine option too. The map makes it efficient to check if a given record is selected.

View original on X