简体   繁体   English

获取当前周/月的日期反应 useEffect

[英]Getting dates of current week/month react useEffect

I have a useEffect(() => { , and I also am using <FullCalendar like this:我有一个useEffect(() => { ,而且我也在使用<FullCalendar像这样:

<FullCalendar
        // CUSTOM BUTTON
        plugins={[ timeGridPlugin ]}
        datesSet={(dateInfo) => {
          console.log(dateInfo.start) //start of the range the calendar date
        }}

Now, what I need is that on the useEffect (on page load), I can call datesSet and get the dates into the useEffect .现在,我需要的是在useEffect (页面加载时)上,我可以调用datesSet并将日期放入useEffect

Is this possible?这可能吗?

datesSet is a fullCalendar option, which allows you to specify a callback function to be run whenever fullCalendar's current date range changes. datesSet是一个 fullCalendar 选项,它允许您指定在 fullCalendar 的当前日期范围更改时运行的回调函数。 So it's effectively an event handler..therefore, you can't call it directly.所以它实际上是一个事件处理程序..因此,您不能直接调用它。 Instead, fullCalendar will run the callback whenever the relevant internal event happens.相反,只要发生相关的内部事件,fullCalendar 就会运行回调。

If you want to get the calendar's current date range at other times, then you can use its view property, which returns a View object, which in turn contains the current start and end dates.如果您想在其他时间获取日历的当前日期范围,则可以使用它的view属性,该属性返回一个 View 对象,该对象又包含当前的开始日期和结束日期。

var view = calendar.view;
var start = view.currentStart;
var end = view.currentEnd;

Documentation:文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM