gpbl / react-day-picker

DayPicker is a customizable date picker component for React. Add date pickers, calendars, and date inputs to your web applications.
https://daypicker.dev
MIT License
5.88k stars 702 forks source link

Hi! I'm not opening new issue because I think it can be somehow related with this one 🙂 #2038

Closed BuhayovA closed 5 months ago

BuhayovA commented 5 months ago

Hi! I'm not opening new issue because I think it can be somehow related with this one 🙂

So, after updating to 8.3.1 this issue appeared: Screenshot 2022-10-05 at 12 00 00

mode and selectedDate comes from props. Their types are defined as follows:

mode?: 'single' | 'multiple' | 'range';
selectedDate: DatesType

(and DatesType: Date | Date[] | DateRange | undefined, where DateRange is imported from `react-day-picker)

At this point I ran out of ideas how to resolve this issue. The only solution that worked, was something like this:

{ mode === 'single' && <DayPicker mode='single' selected={selectedDate as Date | undefined} {...otherProps} /> }
{ mode === 'multiple' && <DayPicker mode='multiple' selected={selectedDate as Date[] | undefined} {...otherProps} /> }
{ mode === 'range' && <DayPicker mode='range' selected={selectedDate as DateRange | undefined} {...otherProps} /> }

but to be hones it doesn't look too clean.

Maybe you would know what is the issue here and if there is a better way to resolve it than the one I showed above?

Thanks in advance 😃

Originally posted by @bartlomiej-bykowy in https://github.com/gpbl/react-day-picker/discussions/1570#discussioncomment-3803763

BuhayovA commented 5 months ago

The problem still hasn't been fixed :(

BuhayovA commented 5 months ago

`import React from 'react' import { DateRange, DayPicker, DayPickerMultipleProps, DayPickerRangeProps, DayPickerSingleProps, } from 'react-day-picker'

export interface PickDateFieldProps { ... }

export interface DayPickerMultipleProps extends PickDateFieldProps { mode: 'multiple' selected?: Date[] onSelect?: (days?: Date[]) => void }

export interface DayPickerSingleProps extends PickDateFieldProps { mode: 'single' selected?: Date onSelect?: (day?: Date) => void }

export interface DayPickerRangeProps extends PickDateFieldProps { mode: 'range' selected?: DateRange onSelect?: (range?: DateRange) => void }

export type DatePickerProps = DayPickerMultipleProps | DayPickerSingleProps | DayPickerRangeProps

const TestDatePicker: React.FC = ({ selected, mode, ...other }) => { // ... return ( <DayPicker mode={mode} selected={selected} {...other} /> ) }

export default TestDatePicker`

Screenshot 2024-01-24 at 12 18 49 PM
gpbl commented 5 months ago

This is already being discussed in https://github.com/gpbl/react-day-picker/discussions/1570#discussioncomment-3803763, please keep the discussion in the relative page. Thanks!