我正在尝试呈现一个列表并为我的 SkillImageTapAction
分配一个索引以供稍后使用,但似乎在每种情况下都只保存了列表中的最后一个索引
这是平面列表
<View style={{ marginTop: 16, marginBottom: 48 }}>
<FlatList
data={matchedHelpers}
renderItem={matchedHelper => renderHelperCell(matchedHelper, props)}
keyExtractor={(matchedHelper: any) => matchedHelper.uid}
numColumns={1}
ListFooterComponent={<ListFooter />}
/>
</View>
这是渲染项
const renderHelperCell = (itemProps, props) => {
const { item } = itemProps;
const { index } = itemProps;
console.log("Index-->",index)
return (
<HelperCell matchedHelper={item} props={props} skillImageTapAction={() => {
setImages(item.matchedSkill.images);
console.log("Index2-->",index)
setTappedIndex(index)
setShowImageSlider(true);
}} />
);
};