React native 在ItemSeparatorComponent中使用索引

React native 在ItemSeparatorComponent中使用索引,react-native,react-native-flatlist,React Native,React Native Flatlist,我试图使用itemseportorcomponent中的当前索引,如下所示,但是index始终为空且从不返回值,但是item已成功填充。如果有人能指出我做错了什么,我会非常感激的 item.id.toString()} renderItem={({item})=>} ItemSeparatorComponent={(项,索引)=>( )} /> 我很确定您刚刚忘记了传递给ItemSeparatorComponent的arrow函数中参数的{} 代码应为: ItemSeparatorCompone

我试图使用
itemseportorcomponent
中的当前索引,如下所示,但是
index
始终为空且从不返回值,但是
item
已成功填充。如果有人能指出我做错了什么,我会非常感激的

item.id.toString()}
renderItem={({item})=>}
ItemSeparatorComponent={(项,索引)=>(
)}
/>

我很确定您刚刚忘记了传递给ItemSeparatorComponent的arrow函数中参数的
{}

代码应为:

ItemSeparatorComponent={({item, index}) => (
        <DateSeparator item={item} index={index} />
)}
ItemSeparatorComponent={({item,index})=>(
)}
编辑:


我错了ItemSeparatorComponent没有获得与renderItem相同的道具。它突出显示了
:boolean,leadingItem:
,但是您仍然需要使用
{}
,以便使它们能够正确地调试。您可以尝试像这样添加一个
调试器

ItemSeparatorComponent={(项目,索引)=>{
调试器
返回(
)
}}

打开Chrome,打开source选项卡,了解
data={messages}

的格式嘿,谢谢你的回复!我尝试包装参数,但这导致属性都返回
未定义
,我只是在我的机器上检查了它,我错了,显然你得到了这样一个对象:
“highlighted”:false,“leadingItem”:object{},
消息
是一个对象数组-FlatList在该数组的
索引
处将每个对象视为一个
-
renderItem
知道索引,但似乎
ItemListSeparator
不知道。