Skip to content

Commit 52e15cb

Browse files
committed
Fix TypeError: get format called on incompatible undefined
Closes #452
1 parent 854e338 commit 52e15cb

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

packages/react-datetime-picker/src/shared/dateFormatter.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ export function getFormatter(
1515
const formatterCacheLocale = formatterCache.get(localeWithDefault);
1616

1717
if (!formatterCacheLocale.has(options)) {
18-
formatterCacheLocale.set(
19-
options,
20-
new Intl.DateTimeFormat(localeWithDefault || undefined, options).format,
21-
);
18+
const formatter = new Intl.DateTimeFormat(localeWithDefault || undefined, options);
19+
20+
formatterCacheLocale.set(options, formatter.format.bind(formatter));
2221
}
2322

2423
return formatterCacheLocale.get(options)(date);
@@ -40,10 +39,9 @@ export function getNumberFormatter(
4039
const numberFormatterCacheLocale = numberFormatterCache.get(localeWithDefault);
4140

4241
if (!numberFormatterCacheLocale.has(options)) {
43-
numberFormatterCacheLocale.set(
44-
options,
45-
new Intl.NumberFormat(localeWithDefault || undefined, options).format,
46-
);
42+
const formatter = new Intl.NumberFormat(localeWithDefault || undefined, options);
43+
44+
numberFormatterCacheLocale.set(options, formatter.format.bind(formatter));
4745
}
4846

4947
return numberFormatterCacheLocale.get(options)(number);

0 commit comments

Comments
 (0)