简体   繁体   English

如何在 react-calender 中使用 tileClassName prop 将 CSS 类应用于 Dates 类型的数组?

[英]How can I use tileClassName prop in react-calender to apply a CSS class to an array of type Dates?

I have an array of type Date.我有一个日期类型的数组。 Any date that is in the array, I want the class "highlight" to be applied to it.数组中的任何日期,我希望将“突出显示”类应用于它。

<Calendar
  onChange={onChange}
  value={value}
  tileClassName={({ date }) => {
    if (dates.find((x) => x.getTime() === date.getTime())) {
       let highlight: string = "highlight";
       return highlight;
    }
   }}
/>

date.getTime() will give you timestamp in milliseconds so there is very thin chance you will find equal values instead you can format the date for eg - "DD-MM-YYYY" then find the date. date.getTime() 会给你以毫秒为单位的时间戳,所以你找到相等值的机会很小,而不是你可以格式化日期为例如 - “DD-MM-YYYY” 然后找到日期。

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

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