简体   繁体   English

如何使用 react-calender 禁用过去日期和未来日期?

[英]How do I disable past dates and future dates using react-calender?

I have tried various ways to implement it but all I could do is disable specifics days in the calendar.我尝试了各种方法来实现它,但我所能做的就是禁用日历中的特定日期。 I want to disable future date and disable all previous dates from today.我想禁用未来日期并禁用从今天开始的所有以前的日期。

To disable past dates you declare this function:要禁用过去的日期,请声明此 function:

const tileDisabled = ({ activeStartDate, date, view }) => {
   return date < new Date()
}

and then you pass it to you calandar like this:然后你像这样把它传给你的日历:

<Calendar tileDisabled={tileDisabled} />

if you want to disbale all the dates (past and future) your function have to return true.如果您想取消所有日期(过去和未来),您的 function 必须返回 true。

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

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