首页 > 解决方案 > 如何修复 react-native-events-calendar 错误

问题描述

我正在使用https://github.com/joshjhargreaves/react-native-event-calendar 在本机反应中制作一个简单的日视图日历。

我有一个外部平板电脑用于使用 Expo 进行测试。运行我的应用程序时,平板电脑上的堆栈跟踪显示错误:

在此处输入图像描述

,但我似乎无法在文件中找到此错误的位置。VS code / metro bundler 没有显示这个错误,它显示了一些警告;

Warning: Failed frame type: The frame `frame.length` is marked as required in `VirtualizedList.getItemLayout`, but its value is `undefined`.

Warning: Failed child context type: Invalid child context `virtualizedCell.cellKey` of type `number` supplied to `CellRenderer`, expected `string`.

我使用导入的代码:

    <View style={styles.calendarHolder}>
    <EventCalendar>
  events={this.state.events}
  width={width}
  initDate={'2017-09-08'}
    </EventCalendar>

</View>

仅当我导入 react-native-events-calendar / 使用它时才会出现此问题。当我不这样做时,我的应用程序工作正常,所以它应该与日历有关。但是,我找不到很多文档,而且由于我也找不到错误的位置,所以我有点卡住了。我怎样才能解决这个问题?对于简单的日视图日历/议程,我也愿意接受其他建议。

标签: react-native

解决方案


您错误地定义了 EventCalendar 组件。像下面这样使用它

<EventCalendar
  events={this.state.events}
  width={width}
  initDate={'2017-09-08'}
/>

代替

<EventCalendar>
 events={this.state.events}
 width={width}
 initDate={'2017-09-08'}
</EventCalendar>

推荐阅读