Skip to content

feat(core/hooks): add 'useSelection' hook#343

Closed
sukvvon wants to merge 3 commits intotoss:mainfrom
sukvvon:feat/use-selection
Closed

feat(core/hooks): add 'useSelection' hook#343
sukvvon wants to merge 3 commits intotoss:mainfrom
sukvvon:feat/use-selection

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Mar 10, 2026

Overview

Add useSelection hook that manages multi-selection state over a list of items. Provides select, deselect, toggle, selectAll, deselectAll, toggleAll, isSelected, isAllSelected, and isSomeSelected.

  • Internal Set<T> for O(1) lookup
  • Values not in items are ignored by select/toggle
  • Auto-syncs selection when items changes (removes stale selections)
  • Stable action references via usePreservedCallback

Checklist

  • Did you write the test code?
  • Have you run yarn run fix to format and lint the code and docs?
  • Have you run yarn run test:coverage to make sure there is no uncovered line?
  • Did you write the JSDoc?

@kimyouknow
Copy link
Collaborator

Thank you for this comprehensive implementation!

After discussion with @zztnrudzz13 , we've decided useSelection falls outside the library's scope. The selection logic (selectAll, toggleAll, isAllSelected, etc.) reflects a specific domain pattern built on top of useSet (which we're accepting as a primitive).

Our goal is to provide primitives that users compose freely — domain-level abstractions like selection management embed assumptions that may not fit every use case.

Same rationale as #338, #233 — see those PRs for context.

If you see it differently or have thoughts on this, we'd love to hear them. We appreciate the effort!

@kimyouknow kimyouknow closed this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants