Skip to content

Commit 5737b61

Browse files
committed
better types
1 parent 9c05884 commit 5737b61

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/compass-components/src/hooks/use-formatted-date.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import { formatDate } from '../utils/format-date';
22

33
import { useState, useEffect } from 'react';
44

5-
export function useFormattedDate(timestamp?: number) {
6-
const [formattedDate, setFormattedDate] = useState(
7-
() => timestamp && formatDate(timestamp)
5+
export function useFormattedDate(timestamp: number): string;
6+
export function useFormattedDate(timestamp?: number): string | undefined {
7+
const [formattedDate, setFormattedDate] = useState(() =>
8+
typeof timestamp === 'number' ? formatDate(timestamp) : undefined
89
);
910

1011
useEffect(() => {
11-
setFormattedDate(timestamp && formatDate(timestamp));
12+
setFormattedDate(
13+
typeof timestamp === 'number' ? formatDate(timestamp) : undefined
14+
);
1215
const interval = setInterval(() => {
13-
setFormattedDate(timestamp && formatDate(timestamp));
16+
setFormattedDate(
17+
typeof timestamp === 'number' ? formatDate(timestamp) : undefined
18+
);
1419
}, 1000 * 60);
1520
return () => {
1621
clearInterval(interval);

0 commit comments

Comments
 (0)