joey
joey

Reputation: 21

onchange issue in react-datepicker with typescript

const [startDate, setStartDate] = useState(new Date());
const [endDate, setEndDate] = useState(null);

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

I want to give 'dates' type. I gave 'dates' number type, but it's not number type. what type should i give 'dates'??

please tell me how to apply TypeScript datePicker..

Upvotes: 1

Views: 1032

Answers (1)

kind user
kind user

Reputation: 41893

The Date object is simply typeof built-in type Date.

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

const [endDate, setEndDate] = useState<Date | null>(null);

const onChange = (dates: [Date, Date]) => {

Upvotes: 1

Related Questions