From f5b4deb36b35bfd0ec5819d740f04775e301e0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9D=B0?= Date: Thu, 24 Oct 2024 16:15:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/twelve-jokes-listen.md | 5 +++++ .../src/components/DatePicker/useDatePicker.ts | 2 +- .../react-native-picker/src/date-picker/useDatePicker.ts | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/twelve-jokes-listen.md 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?.(); };