Skip to content

Commit 1790bce

Browse files
committed
Display placeholder for time values until client-side rendering is complete
1 parent 3ff2a71 commit 1790bce

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

components/Clock.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export default function Clock({
99
hasSeconds?: boolean;
1010
showSubtext?: boolean;
1111
}) {
12+
const [isClient, setIsClient] = useState(false);
13+
14+
useEffect(() => {
15+
setIsClient(true);
16+
}, []);
17+
1218
const getTimeParts = () => {
1319
const now = new Date();
1420
return {
@@ -36,7 +42,7 @@ export default function Clock({
3642
) : (
3743
""
3844
)}
39-
{time.hours}
45+
{isClient ? time.hours : "##"}
4046
</span>
4147

4248
<span className="hidden md:inline">:</span>
@@ -46,7 +52,7 @@ export default function Clock({
4652
{showSubtext && (
4753
<small className="-bottom-2.5 absolute text-sm">minutes</small>
4854
)}
49-
{time.minutes}
55+
{isClient ? time.minutes : "##"}
5056
</span>
5157

5258
{hasSeconds ? (
@@ -58,7 +64,7 @@ export default function Clock({
5864
{showSubtext && (
5965
<small className="-bottom-2.5 absolute text-sm">seconds</small>
6066
)}
61-
{time.seconds}
67+
{isClient ? time.seconds : "##"}
6268
</span>
6369
</>
6470
) : (

0 commit comments

Comments
 (0)