React Aria. Collection API. How to access the index of an element in an array? #6540
-
Sometimes it is necessary to have a dynamic index of the current element, for example to mark nested fields in complex form data, since it must start with <Collection items={items}>
{variant => (
<FieldGroup style={styles.fieldgroup}>
<TextField name={`variants.${items.indexOf(variant)}.name`} type="text" isRequired defaultValue={variant.name} />
</FieldGroup>
)}
</Collection> It would be nice if renderProp had idx as the second argument: <Collection items={items}>
{(variant, idx) => ()}
</Collection> |
Beta Was this translation helpful? Give feedback.
Answered by
snowystinger
Jun 14, 2024
Replies: 1 comment
-
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
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
predaytor
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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