farhoudshapouran / react-native-ui-datepicker

Customizable React Native 📅 DatePicker component for Android, iOS, and Web. It includes single, range and multiple modes and supports different locales.
https://farhoudshapouran.github.io/react-native-ui-datepicker/
MIT License
267 stars 27 forks source link

the 'date' param of 'onChange' is not a javascript Date object #91

Open YaoHuiJi opened 1 month ago

YaoHuiJi commented 1 month ago

Would returning a standard JavaScript Date type instead of dayjs object be more appropriate? Otherwise, it could be unintuitive and inconvenient for users who don't use the dayjs library(they have to use param.date.toDate() which is not mentioned in the document)

And I also found that when set timePicker=true, the param.date of onChange is a string? These behaviors are inconsistent, unintuitive and inconvenient. Is it designed this way for some reason?

thecodecafe commented 4 weeks ago

@YaoHuiJi I had the same thought, I want to use this library but the only thing turning me away is the dependency on DaysJS. The standard Date object in Javascript should be the date object used.

GustavoBonfimS commented 1 week ago

It would be interesting if the onChange output was a javascript Date object, or at least sent as another parameter.

Can the project maintainers discuss this? It would be great to hear their opinion on this.

GustavoBonfimS commented 1 week ago

It seems to be possible to use the Date object with this little workaround

function DatePickerModal({
    modal: { getParam },
}: ModalProps<"DatePickerModal">) {
  const defaultDate = getParam("date");
  const [selectedDate, setSelectedDate] = useState(defaultDate ?? new Date());

  return (
     <DefaultContainer variant="modal">
    <DateTimePicker
            onChange={({ date }) => {
              setSelectedDate(new Date(date as string));
            }}
           date={selectedDate}
           mode="single"
           locale="pt-br"
         />

       <Button>Confirmar</Button>
    </DefaultContainer>
    );
}

export default DatePickerModal;