如何使用Reactjs将日历的日期状态发送到另一个日历? [英] How to send the date state of calendar to another calendar with Reactjs?
问题描述
我有两个日历,例如议程,有一个图标日历按钮,当我点击它时,它会被重定向到另一个日历(规划)
,这些日历是使用 react-big-calendar 开发的,我希望当我在例如导航时议程的一周 juin 17 - 23
,点击图标日历,它将被重定向到 juin 17 - 23
of the Planning。
I have two calendars, such as the Agenda, have an icon calendar button, when I click on it, it will be redirected to another calendar (Planning)
, these calendars are developed with react-big-calendar, I want when I navigate for example on the week of juin 17 - 23
of Agenda and I click on the icon calendar, it will be redirected to juin 17 - 23
of the Planning.
我的代码是: https ://codesandbox.io/s/m7k904y3o8
我尝试用 getWeek()发送日期
,但它不起作用。
I try to send the date with getWeek()
, but it doesn't work.
我该如何解决?
推荐答案
您可以将其他数据添加到 this.props.history.push
,然后将在位置$ c中提供您的
Planning
组件上的$ c> prop。例如,如果您想查看1995年12月20日的周:
You can add additional data to this.props.history.push
which will then be available in the location
prop on your Planning
component. For example if you want to view the Week of the 20th December 1995:
// 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 });
}
这篇关于如何使用Reactjs将日历的日期状态发送到另一个日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!