headplane/app/utils/useLiveData.ts

17 lines
337 B
TypeScript
Raw Normal View History

2024-03-25 18:47:15 -04:00
import { useRevalidator } from '@remix-run/react'
import { useInterval } from 'usehooks-ts'
type Properties = {
interval: number;
}
export function useLiveData({ interval }: Properties) {
const revalidator = useRevalidator()
useInterval(() => {
if (revalidator.state === 'idle') {
revalidator.revalidate()
}
}, interval)
}