update
This commit is contained in:
@@ -16,19 +16,14 @@ interface DatePickerProps {
|
||||
}
|
||||
|
||||
export function DatePicker({ className, value, onChange }: DatePickerProps) {
|
||||
const [date, setDate] = React.useState<Date | undefined>(
|
||||
value ? new Date(typeof value === 'string' ? value : value.toISOString()) : undefined
|
||||
)
|
||||
const toDate = (val: string | Dayjs | undefined): Date | undefined => {
|
||||
if (!val) return undefined
|
||||
return new Date(typeof val === 'string' ? val : val.toISOString())
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (value) {
|
||||
const dateValue = typeof value === 'string' ? value : value.toISOString()
|
||||
setDate(new Date(dateValue))
|
||||
}
|
||||
}, [value])
|
||||
const date = toDate(value)
|
||||
|
||||
const handleSelect = (selectedDate: Date | undefined) => {
|
||||
setDate(selectedDate)
|
||||
if (selectedDate && onChange) {
|
||||
onChange(dayjs(selectedDate))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user