小编典典

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

reactjs

我有两个日历,例如“议程”,有一个图标日历按钮,当我单击它时,它将重定向到另一个日历(Planning),这些日历是使用react-big-
calendar
开发的,例如当我在juin 17 - 23议程的一周,然后单击图标日历,它将重定向到juin 17 - 23“计划”。

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

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

我该如何解决?


阅读 233

收藏
2020-07-22

共1个答案

小编典典

您可以添加其他数据this.props.history.push,然后可以在组件location上的prop中使用这些数据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参数Query参数

2020-07-22