mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Remove infinite loop in useFromNow
This commit is contained in:
parent
f444470a2c
commit
77da19ad20
@ -7,10 +7,12 @@ export function useFromNow(date: Date): string {
|
||||
const detailed = fromNowDetailed(date);
|
||||
|
||||
useEffect(() => {
|
||||
const timeout = setTimeout(() => {
|
||||
setInvalidationCounter(invalidationCounter + 1);
|
||||
}, Math.round(detailed.secondsUntilChange * 1000));
|
||||
return () => clearTimeout(timeout);
|
||||
if (Number.isFinite(detailed.secondsUntilChange)) {
|
||||
const timeout = setTimeout(() => {
|
||||
setInvalidationCounter(invalidationCounter + 1);
|
||||
}, Math.round(detailed.secondsUntilChange * 1000));
|
||||
return () => clearTimeout(timeout);
|
||||
}
|
||||
}, [invalidationCounter, detailed.secondsUntilChange]);
|
||||
|
||||
return detailed.result;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user