简体   繁体   中英

React Native flatlist specific data

Im requiring data from a local json file just for test purposes (On a ideal world im going to fetch data from a remote url) this json file is an array with 8 objects, but I need the flatlist just to render the first 3, how can I do that?

My code:

import extratoData from "./extratoData.json"

export default function Body () {
  const [data, setData] = useState([])

  useEffect(() => {setData(extratoData)}, [])

  return(
   <FlatList 
    data={extratoData} 
    renderItem={({item}) => <ExtratoRenderItem title={item.title} amount={item.amount} date={item.date} time={item.time} cashback={item.cashBack}/>}
    keyExtractor={(item, index) => index.toString()}
   />
)

您可以只使用Array.prototype.slice()方法。

  var firstThree = extratoData.slice(0, 3);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM