14c880123c
Expo app with dashboard, time clock, invoices, and settings — native tabs, glass UI, theme-aware components, and iOS Live Activities. Co-authored-by: Cursor <cursoragent@cursor.com>
22 lines
488 B
TypeScript
22 lines
488 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
function formatClockTime(date: Date) {
|
|
return date.toLocaleTimeString(undefined, {
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
});
|
|
}
|
|
|
|
export function useLiveClock() {
|
|
const [time, setTime] = useState(() => formatClockTime(new Date()));
|
|
|
|
useEffect(() => {
|
|
const tick = () => setTime(formatClockTime(new Date()));
|
|
tick();
|
|
const id = setInterval(tick, 15_000);
|
|
return () => clearInterval(id);
|
|
}, []);
|
|
|
|
return time;
|
|
}
|