react-multi-date-picker
react-multi-date-picker copied to clipboard
Typescript support in onChange method for datepicker
I'm using DatePicker in my typescript react project and facing an issue regarding onChange method.
It returns DateObject so in order to do something with it we have to format/parse it. So I'm using .unix method but Typescript says Property 'unix' does not exist on type 'DateObject | DateObject[]'. Property 'unix' does not exist on type 'DateObject[]'.ts(2339)
my DatePicker component:
Datepicker props
type Props = {
onChange?(selectedDates: DateObject | DateObject[] | null): void;
value: DateObject | DateObject[] | Date | string[] | null | string | number;
format?: string;
};
<DatePicker
value={value}
onChange={(dates)=>(onChange(dates.unix))}
format={format}
/>
May be my approach is wrong so don't hesitate to point it out