Invokes a callback periodically while the component is mounted.
All functions scheduled with the same delay are invoked synchronously across all components that use this hook.
The callback argument types.
The callback to invoke.
The delay, in milliseconds, between invocations.
Arguments passed to the callback.
const [count, setCount] = useState(0);// Increment the counter every second while the component is mounteduseIntervalCallback( step => setCount(prevCount => prevCount + step), 1000, // Interval delay in milliseconds 1 // Argument passed to the callback); Copy
const [count, setCount] = useState(0);// Increment the counter every second while the component is mounteduseIntervalCallback( step => setCount(prevCount => prevCount + step), 1000, // Interval delay in milliseconds 1 // Argument passed to the callback);
useInterval
Invokes a callback periodically while the component is mounted.
All functions scheduled with the same delay are invoked synchronously across all components that use this hook.