diff --git a/.changeset/twelve-jokes-listen.md b/.changeset/twelve-jokes-listen.md new file mode 100644 index 000000000..9a7b0bf62 --- /dev/null +++ b/.changeset/twelve-jokes-listen.md @@ -0,0 +1,5 @@ +--- +'@td-design/react-native-picker': patch +--- + +fix: 修复日期组件的bug diff --git a/packages/react-native-picker/src/components/DatePicker/useDatePicker.ts b/packages/react-native-picker/src/components/DatePicker/useDatePicker.ts index 9d6c073de..8d30bdae8 100644 --- a/packages/react-native-picker/src/components/DatePicker/useDatePicker.ts +++ b/packages/react-native-picker/src/components/DatePicker/useDatePicker.ts @@ -19,7 +19,7 @@ export default function useDatePicker({ const minDayjs = useMemo(() => dayjs(minDate), [minDate]); const maxDayjs = useMemo(() => dayjs(maxDate), [maxDate]); - const [tempValue, setTempValue] = useSafeState(value); + const [tempValue, setTempValue] = useSafeState(value ?? new Date()); const clipDate = (date: Date) => { if (mode === 'datetime') { diff --git a/packages/react-native-picker/src/date-picker/useDatePicker.ts b/packages/react-native-picker/src/date-picker/useDatePicker.ts index 5e1094cf4..6771e70d5 100644 --- a/packages/react-native-picker/src/date-picker/useDatePicker.ts +++ b/packages/react-native-picker/src/date-picker/useDatePicker.ts @@ -31,7 +31,8 @@ export default function useDatePicker({ }; const handleOk = () => { - onChange?.(date, dayjs(date).format(format)); + const value = date ?? new Date(); + onChange?.(value, dayjs(value).format(format)); onClose?.(); };