Hooks

usePolling

Publisher

cermuel

50 hooks published

More from this publisher

usePolling

Refresh data while respecting page and connection state.

usePolling.tsx
import { usePolling } from "@cermuel/hooks/react";export function usePollingExample() {  async function fetchUser() { return { name: 'Ada' }; }  const polling = usePolling(fetchUser, { interval: 5000 });  return <p>{polling.running ? "Polling" : "Paused"}</p>;}

Props

Param
Type
Default Value
fn
() => Promise<TResult>
options?
PollingOptions
{}

Returns

{ running: boolean; start: () => void; stop: () => void; status: AsyncStatus; data: TResult | null; error: Error | null; loading: boolean; execute: () => Promise<TResult>; reset: () => void; }