【问题标题】:onchange issue in react-datepicker with typescript带有打字稿的 react-datepicker 中的 onchange 问题
【发布时间】:2022-10-21 20:16:43
【问题描述】:
const [startDate, setStartDate] = useState(new Date());
const [endDate, setEndDate] = useState(null);

const onChange = (dates: [? | ?]) => {
  const [start, end] = dates;
  setStartDate(start);
  setEndDate(end);
};

我想给出“日期”类型。 我给出了“日期”数字类型,但它不是数字类型。 我应该给出什么类型的“日期”?

请告诉我如何应用 TypeScript datePicker..

【问题讨论】:

    标签: reactjs typescript datepicker


    【解决方案1】:

    Date 对象只是 typeof 内置类型 Date

    const [startDate, setStartDate] = useState<Date>(new Date());
         // ^^^^^ will be typeof Date
    
    const onChange = (dates: [Date, Date]) => {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-16
      • 2016-11-09
      • 2021-08-12
      • 2020-06-13
      • 2015-10-23
      • 1970-01-01
      相关资源
      最近更新 更多