简体   繁体   English

date.format 不是 function 反应日期

[英]date.format is not a function reacr-dates

I was trying to use singleDatePicer from react-dates,which is a popular date picker library by airbnb, on selecting a date, it throws the error date.format is not a function , and just breaks, my code sandbox link is -> https://08cg1.csb.app/ .我试图使用 react-dates 中的 singleDatePicer,它是 airbnb 的一个流行的日期选择器库,在选择日期时,它会抛出错误date.format is not a function ,并且只是中断,我的代码沙箱链接是 -> https ://08cg1.csb.app/ Thanks in Advance.提前致谢。

singleDatePicker will accept moment object as date props so you need to change onDateChange like below:- singleDatePicker将接受时刻 object 作为date道具,因此您需要更改onDateChange如下:-

onDateChange={(date) => setDate(date)};
onDateChange={(date) => {setDate(date);}}

Here, Don't change the date format and then set the state.在这里,不要更改日期格式,然后设置 state。 Just set the state directly.直接设置state即可。

If you want to display that selected date somewhere else, there use the moment .如果您想在其他地方显示所选日期,请使用moment

The issue was, once you changed the date format, that format is not supporting as value.问题是,一旦您更改了日期格式,该格式就不支持作为值。

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

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