I am working with a basic state structure:
{
items: Item[]
selectedItems: string[]
}
In my application, I have a list of items with checkboxes. When I select an item, the list state is updated to include that item in the selected items array. However, I encounter an issue when I navigate deeper into an item for editing.
After editing an item and returning to the list view, I can still see the correct state with the previously selected items intact. But when I attempt to deselect an item, the reducer does not seem to update the state as expected.
The reducer function responsible for updating the selection looks like this:
on(addItemToSelection, (state, { id, checked }) => ({
...state,
selectedItems: checked ? [...state.selectedItems, id] : state.selectedItems.filter((itemId) => itemId !== id)
})