diff --git a/packages/react-use/src/use-date-format/format-date.ts b/packages/react-use/src/use-date-format/format-date.ts index 98b3f08..27a73a5 100644 --- a/packages/react-use/src/use-date-format/format-date.ts +++ b/packages/react-use/src/use-date-format/format-date.ts @@ -130,7 +130,7 @@ export const formatDate = (date: Date, formatStr: string, options: FormatDateOpt export type DateLike = Date | number | string -export function normalizeDate(date: DateLike) { +export function normalizeDate(date: DateLike | null | undefined): Date { if (date === null) return new Date(Number.NaN) // null is invalid if (date === undefined) return new Date() if (date instanceof Date) return new Date(date) diff --git a/packages/react-use/src/use-date-format/index.ts b/packages/react-use/src/use-date-format/index.ts index 88c0e63..39145f7 100644 --- a/packages/react-use/src/use-date-format/index.ts +++ b/packages/react-use/src/use-date-format/index.ts @@ -26,7 +26,7 @@ export function useDateFormat( /** * a date object or a date string */ - date: DateLike, + date: DateLike | null | undefined, /** * format string *