useInterval
A declarative interval hook based on Dan Abramov's article on overreacted.io. The interval can be paused by setting the delay to null.
Usage
import { useInterval } from "@reactuses/core";
const Demo = () => {
const [count, setCount] = useState(0);
useInterval(() => {
setCount(count + 1);
}, 1000);
return <div>count: {count}</div>;
};
Example
count: 0
Type Declarations
export default function useInterval(
callback: () => void,
delay?: number | null,
options?: {
immediate?: boolean
}
): void