在RN中制作FlashList自定义组件

问题描述 投票:0回答:1

当然我们都很好。我在 React Native 中使用 FlashList 作为自定义组件,以便它可以在所有屏幕上使用,但我遇到了错误。

************FlashList 自定义组件

道具如下:

  1. “dataObject”是将传递给 FlashList 的 data 属性的 api 响应

  2. “dataList”是另一个设计为在 FlashList 的 renderItem 属性中呈现的组件,即一个样式设置为显示上面的 dataObject Props 返回的数据的组件,它以 item 作为参数。

  3. estimatedItemSize 是根据 FlashList 指定和指示首次获取的屏幕要获取的项目数。

import React, {PropsWithChildren} from 'react'
import {FlashList} from '@shopify/flash-list';

type FlashListProps = {
    dataObject: any[];
    dataList: React.ReactNode;
    estimatedItemSize: number;  
  }

const DataFlashList = (Props: PropsWithChildren<FlashListProps>) => {
  return <>
        <FlashList 
  data={Props.dataObject}
  renderItem={({item}) => {
    {Props.children}
}}

  estimatedItemSize={Props.estimatedItemSize}

/>
  </>
}

export default DataFlashList

*******ERROR 

The renderItem property of the FlashList is underlined as error that goes below :

Type '({ item }: ListRenderItemInfo<any>) => void' is not assignable to type 'ListRenderItem<any>'.
  Type 'void' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>> | null'

The expected type comes from property 'renderItem' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FlashList<any>> 

***我的期望

即使抛开我遇到的错误,我也在考虑如何像往常一样传递“Props.Children”中的“item”参数,因为我将使用它来获取从 api 返回的“Props.dataObject”的属性。

感谢您的协助。

typescript react-native flash-list
1个回答
0
投票

你没有归还 小朋友们请学习如何归还功能

© www.soinside.com 2019 - 2024. All rights reserved.