How to use unique identifier in key prop when mapping splitAtom ? #1602
-
I'm using splitAtom to handle tabs reordering, adding and removing. const tabsAtom = atom<TabItem[]>([
{ id, type, data, ....},
{ id, type, data, ....},
{ id, type, data, ....},
])
const tabsAtomsAtom = splitAtom(tabsAtom)
// in component
const [tabsAtoms, dispatch] = useAtom(tabsAtomsAtom)
<ScrollView>
{tabsAtoms.map(
(tabAtom, i) =>
<TabPreview
key={i}
index={i}
tabAtom={tabAtom}
tapGestureRef={tapGestureRefs[i]}
simultaneousHandlers={scrollViewRef}
onPress={onItemPress}
onDelete={onDeleteItem}
/>
)}
</ScrollView> I'm using reanimated to animate entering / exiting animations, but it fail to work properly. Is there any way to use an atom unique identifier ? |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Nov 29, 2022
Replies: 1 comment 7 replies
-
That's what const tabsAtomsAtom = splitAtom(tabsAtom, item => item.id)
{tabsAtoms.map(
(tabAtom, i) =>
<TabPreview
key={`${tabAtom}`} |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
smontlouis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's what
keyExtractor
is for.