DEMO
Count - 0
useInterval
Run a function repeatedly at a specified interval.
Use the immediate
option to run the function immediately when it is updated.
Usage
import { useInterval } from '@react-hooks-library/core'
function Demo() {
const [count, setCount] = useState(0)
const increment = useCallback(() => setCount((c) => c + 1), [])
useInterval(increment, 1000)
return <div>Count - {count}</div>
}
Options
immediate
- when true, the callback will execute on before setting a timerpaused
- pause the execution of your callback
Type Declarations
declare type UseIntervalOptions = {
immediate: boolean
paused: boolean
}
/**
* Run a function repeatedly at a specified interval.
*
* @see https://react-hooks-library.vercel.app/core/useInterval
*/
declare function useInterval<T extends () => void>(
callback: T,
delay: number,
options?: Partial<UseIntervalOptions>
): void