Select items of a list, one by one or all at once, and know which are selected.
This is custom React hooks, you need to follow the Basic Rules when you use it.
Toggle items or select them all.
const useSelection = <T>(options: {
data: T[]
initialSelection?: T[]
}) => [
T[],
{
select: (item: T) => void
deselect: (item: T) => void
toggle: (item: T) => void
selectAll: () => void
deselectAll: () => void
setSelection: (items: T[]) => void
isSelected: (item: T) => boolean
},
]