最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - this.props.getItemCount is not a function (VirtualizedList, React Native) - Stack Overflow

programmeradmin2浏览0评论

I switched from using a FlatList to a VirtualizedList, and I got the error this.props.getItemCount is not a function. When I ran the debugger, the exception is thrown from VirtualizedList.js

<VirtualizedList
    data={contacts}
    getItem={(data, index) => data[index]}
    getItemCount={data => data.length}
    renderItem={({ item }) => (
        <ContactListItem
        name={item.name}
        number={item.number}
        />
    )}
/>

I switched from using a FlatList to a VirtualizedList, and I got the error this.props.getItemCount is not a function. When I ran the debugger, the exception is thrown from VirtualizedList.js

<VirtualizedList
    data={contacts}
    getItem={(data, index) => data[index]}
    getItemCount={data => data.length}
    renderItem={({ item }) => (
        <ContactListItem
        name={item.name}
        number={item.number}
        />
    )}
/>
Share Improve this question asked Aug 25, 2018 at 18:04 brownmagik352brownmagik352 3963 silver badges12 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

Unlike FlatList, VirtualizedList requires the props getItem and getItemCount (React Native Docs).

<VirtualizedList
    data={contacts}
    getItem={(data, index) => data[index]}
    getItemCount={data => data.length}
    renderItem={({ item }) => (
        <ContactListItem
        name={item.name}
        number={item.number}
        />
    )}
/>

If you used VirtualizedList and you still have the same error, use SafeAreaView import it from react-native and add FlatList inside it

import {FlatList,SafeAreaView} from 'react-native';
<SafeAreaView>
  <FlatList
    keyExtractor={(item, i) => item.id.toString()}
    data={favoriteFilm}
    renderItem={({item}) => (
      <FavoritesItemFilm
        title={item.title}
        description={item.overview}
        vote={item.vote_count}
        release={item.release_date}
        image={item.poster_path}
        id={item.id}
      />
    )}
  />
</SafeAreaView>
发布评论

评论列表(0)

  1. 暂无评论