当数据为空时,是否可以呈现备用组件?我不只是呈现列表或不呈现列表的唯一原因是,在这两种情况下(data.length!data.length)都需要ListHeaderComponent...

const data = []
<FlatList
  contentContainerStyle={styles.list}
  data={data} // if empty or !data.length render <ZeroComponent/>

推荐答案

UPDATE

const data = []
_listEmptyComponent = () => {
    return (
        <View>
            // any activity indicator or error component
        </View>
    )
}

<FlatList
    data={data}
    ListEmptyComponent={this._listEmptyComponent}
    contentContainerStyle={styles.list} 
/>
const data = []

renderFooter = () => {
  if (data.length != 0) return null;


  return (
    <View>
      // any activity indicator or error component
    </View>
   );
};

<FlatList
    contentContainerStyle={styles.list}
    data={data}
    ListFooterComponent={this.renderFooter}
/>

希望这有帮助

React-native相关问答推荐

react native 如何更新倒置平面列表的数组中的项目

加载作为props传递的图像

使用 react-native 设置 Select 器的高度

使用直接在 Windows 中运行的模拟器在 WSL 中运行 React Native

是否可以在 React Native 中隐藏BugReporting extraData?

在使用 redux-persist 重新水化存储之前加载初始状态的默认值

@react-navigation/stack 与 @react-navigation/native-stack 有什么区别?

textAlignVertical不是有效的样式属性

试图注册两个同名的视图 RNGestureHandlerButton

React Native Remote Debugger 在 Chrome 中显示缓存的包

使用 React Navigation 制作离开屏幕的动画

使用离线包在 iOS 设备上运行 react-native 应用程序

react native如何访问文件系统?

我可以将标题传递给图像源吗?

React Native require(image) 返回数字

React Native 不支持在 Windows 上开发?

如何在 react-native 中为在后台杀死的 android 应用程序保持状态

react-native:多色文本视图

react-native:如何覆盖组件中定义的默认样式

如何从react-native应用程序打开外部应用程序?