Closed stephenh closed 3 years ago
This seems reasonable. We generally try to avoid accessing collections by index where possible because indices can change as items are added, removed, or re-arranged within the collection. But your usecase seems like it would be ok because the indices are only used during rendering and not persisted anywhere.
🙋 Feature Request
Add a way to do index-based lookups to
@react-types
Collection
.Collection
's docs, "A generic interface to access a readonly sequential collection of unique keyed items", make it sound like doing an index-based lookup would be kosher.🤔 Expected Behavior
Just do a lookup.
😯 Current Behavior
We have to convert
collection.getKeys
to an array, and do an index-based look up on the array to get the key, thenCollection.getItem(key)
:🔦 Context
We're integrating
useListBox
/useMultipleSelectionState
with react-virtuoso for virtualized rendering, and the virtuoso api has aitemContent: (index) => ReactNode
method, that we want to implement by doingstate.collection.getAt(index)
, wherestate
is aSelectState
.