我有一个FlatList,我想根据方向改变列数.然而,当我这样做的时候,我会看到红色的屏幕.根据红屏错误信息,我不太确定应该如何更改按键.感谢您的帮助.

      // dynamically changing number of columns
      const numCols = orientation === constants.PORTRAIT ? 3 : 8

      <FlatList
        keyExtractor={(_, i) => i}
        numColumns={numCols} // assigning the number of columns
        horizontal={false}
        renderItem={({ item }) => <ListItem imageUrl={item.url} />}
      />}

red screen of death

推荐答案

documentation开始,看起来你应该这样做

key={(this.state.horizontal ? 'h' : 'v')}

React-native相关问答推荐

如何在EXPO路由中重置导航

我们如何才能将我们自己的应用程序(IOS)排除在共享表中?

未执行迁移?

React native + react-query + onError 不捕获并处理错误?

React Native:任务 ':app:checkDebugDuplicateClasses' 执行失败

使用动画标记时如何优化react 本机 map 性能

如何在 react-navigation v6 中更改标题高度

如何在带有decorator 的 react-native 0.56 (Babel 7) 中使用 mobx

React Native 上传到 S3 存储空间

TypeError:传播不可迭代实例的无效try

library not found for -lRCTGeolocation

Realm 和 React Native - 实现自动更新的最佳实践?

NativeBase + Exponent Header

有没有办法改变 IOS 标题上react-navigation 的默认后退按钮 colored颜色 ?

如何在 React Native 中获取电话号码?

是否可以在 react-native 的构造函数中调用异步函数?

在 react-native 中设置动态 'initialRouteName'

Unexpected token on "export default const"

运行时尚未准备好进行调试

React Native - __DEV__ 未定义