编程语言
首页 > 编程语言> > javascript-如何使用Reactjs将日历的日期状态发送到另一个日历?

javascript-如何使用Reactjs将日历的日期状态发送到另一个日历?

作者:互联网

我有两个日历,例如“议程”,有一个图标日历按钮,当我单击它时,它将重定向到另一个日历(“计划”),这些日历是使用react-big-calendar开发的,例如当我在一周中导航时,我想议程的6月17日至23日,我单击图标日历,它将重定向到规划的6月17日至23日.

我的代码是:https://codesandbox.io/s/m7k904y3o8

我尝试使用getWeek()发送日期,但是它不起作用.

我该如何解决?

解决方法:

您可以将其他数据添加到this.props.history.push中,然后可在Planning组件上的位置属性中使用.例如,如果要查看1995年12月20日的一周:

// Agenda.js: Routing to "/planning"

this.props.history.push("/planning", { date: new Date(1994, 11, 19, 0, 0)})
// Planning.js

constructor(props) {
    super(props); //Important

    this.state({
        /* ... */
        dateWeek: this.props.location.state && this.props.location.state.date
    });
}

// Following is a fix or else you would not get next/previous week.

getThisWeek = (dateWeek) => {
    this.setState({ dateWeek });
}

我建议使用的其他两个解决方案是URL parametersQuery parameters.

标签:javascript,reactjs,state,react-props,react-big-calendar
来源: https://codeday.me/bug/20191014/1911593.html