React fullCalendar,在 eventReceive 函数中达到 this.props

React fullCalendar, reaching this.props in eventReceive function

我想用事件的开始时间设置我的 parent 的属性之一,但我无法从 function(info) 方法内部到达 this.props。我怎样才能找到我想使用的方法?

eventReceive={function (info) {
                this.props.onChangeStartDate(info.start);
              }}

onChangeStartDate 是我的 parent 的功能之一,它在 parent 组件中设置约会的开始日期,我想提供我刚刚添加到日历中的事件数据作为该函数的参数。

我收到以下错误:

Cannot read property 'onChangeAppointment' of undefined

感谢您的帮助。

以下将解决您的错误。

eventReceive={(info) => {
    this.props.onChangeStartDate(info.start);
}}

在哪里 () => {}是常用的箭头函数。参见 documentation

发生错误的原因是您在函数范围内丢失了 this 的上下文。