如何解决“尝试获取超出范围索引 NaN 的框架” - 反应原生平面列表?
下面是使用的代码,打开此页面时会出现“尝试获取超出范围索引 NaN 的框架”。
我不明白我的问题出在哪里。请帮忙。
import {FlatList} from 'react-native-gesture-handler';
import {SIZES, constants} from '../../constants';
const [row1Images, setRow1Images] = React.useState({
...constants.walkthrough_01_01_images,
...constants.walkthrough_01_01_images
})
const row1FlatListRef = React.useRef()
<FlatList
ref={row1FlatListRef}
decelerationRate="fast"
horizontal
showsHorizontalScrollIndicator={false}
listKey="Slider1"
keyExtractor={(_, index) => `Slider1_${index}`}
data={row1Images}
renderItem={({item, index}) => {
return (
<View style={{width: ITEM_WIDTH,alignItems: "center",justifyContent: "center"}}>
<Image source={item} style={{width: 110,height: 110}} />
</View>
)
}}
/>
here below is the code which was used, on open this page then it appears that 'Tried to get frame for out of range index NaN'.
I don't understand where I got the issues. Please help.
import {FlatList} from 'react-native-gesture-handler';
import {SIZES, constants} from '../../constants';
const [row1Images, setRow1Images] = React.useState({
...constants.walkthrough_01_01_images,
...constants.walkthrough_01_01_images
})
const row1FlatListRef = React.useRef()
<FlatList
ref={row1FlatListRef}
decelerationRate="fast"
horizontal
showsHorizontalScrollIndicator={false}
listKey="Slider1"
keyExtractor={(_, index) => `Slider1_${index}`}
data={row1Images}
renderItem={({item, index}) => {
return (
<View style={{width: ITEM_WIDTH,alignItems: "center",justifyContent: "center"}}>
<Image source={item} style={{width: 110,height: 110}} />
</View>
)
}}
/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将
row1Images
设置为对象,而不是数组。传递给FlatList
的data
属性应该是一个数组。像这样设置 row1Images
You were set
row1Images
as an object instead of array.data
props passed toFlatList
should be an array.Set
row1Images
like this