mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
27 lines
589 B
TypeScript
27 lines
589 B
TypeScript
import { useCallback, useEffect } from 'react';
|
|
|
|
import { useRevalidator } from 'react-router';
|
|
|
|
/**
|
|
* Not really used anymore, this causes random 500s when the user refreshes while this occurs.
|
|
*/
|
|
export const RefreshOnFocus = () => {
|
|
const { revalidate, state } = useRevalidator();
|
|
|
|
const onFocus = useCallback(() => {
|
|
if (state === 'idle') {
|
|
void revalidate();
|
|
}
|
|
}, [revalidate]);
|
|
|
|
useEffect(() => {
|
|
window.addEventListener('focus', onFocus);
|
|
|
|
return () => {
|
|
window.removeEventListener('focus', onFocus);
|
|
};
|
|
}, [onFocus]);
|
|
|
|
return null;
|
|
};
|