Skip to content

React Aria. Collection API. How to access the index of an element in an array? #6540

Answered by snowystinger
predaytor asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately, if we provide/track the index, then we lose some of our ability to cache. Instead, it's best to keep an index map yourself

let items = [...]
let indexMap = new Map();
items.forEach((item, index) => indexMap.set(item, index)); // you can memo this

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by predaytor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants