In forklift-ui, we use useSelectionState for both checkbox selections and row expansions in tables because the state requirements are exactly the same. However, the functions returned from this hook are named very specifically for selection, so it might be nice to make them more generic (toggleItem, isItemToggled, toggleAll etc) and avoid confusing renames in destructuring like this one:
const {
toggleItemSelected: toggleVMExpanded,
isItemSelected: isVMExpanded,
selectAll: expandAll,
} = useSelectionState<SourceVM>({
items: sortedItems,
isEqual: (a, b) => a.selfLink === b.selfLink,
});
We could then create thin wrappers with specific naming if we want, like useSelectionState, useExpansionState, etc. Or we could have these functions returned in an array so they can be named on the fly, but there are so many...
In forklift-ui, we use
useSelectionStatefor both checkbox selections and row expansions in tables because the state requirements are exactly the same. However, the functions returned from this hook are named very specifically for selection, so it might be nice to make them more generic (toggleItem,isItemToggled,toggleAlletc) and avoid confusing renames in destructuring like this one:We could then create thin wrappers with specific naming if we want, like
useSelectionState,useExpansionState, etc. Or we could have these functions returned in an array so they can be named on the fly, but there are so many...