mirror of
https://github.com/docmost/docmost.git
synced 2025-11-17 02:21:09 +10:00
* time ago hook
This commit is contained in:
16
apps/client/src/hooks/use-time-ago.tsx
Normal file
16
apps/client/src/hooks/use-time-ago.tsx
Normal file
@ -0,0 +1,16 @@
|
||||
import { timeAgo } from "@/lib/time.ts";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useTimeAgo(date: Date | string) {
|
||||
const [value, setValue] = useState(() => timeAgo(new Date(date)));
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setValue(timeAgo(new Date(date)));
|
||||
}, 5 * 1000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [date]);
|
||||
|
||||
return value;
|
||||
}
|
||||
Reference in New Issue
Block a user