headplane/app/utils/useLiveData.ts
2024-03-25 18:54:04 -04:00

17 lines
337 B
TypeScript

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)
}