# extendify/3.2.1/src/AutoLaunch/hooks/useRateLimitedCursor.js

Extendify, version 3.2.1. 32 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.2.1/code/src/AutoLaunch/hooks/useRateLimitedCursor.js
- Raw: https://pluginprobe.com/plugins/extendify/3.2.1/raw/src/AutoLaunch/hooks/useRateLimitedCursor.js
- Modified: 2026-02-26T23:48:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/3.2.1/code/src/AutoLaunch/hooks/useRateLimitedCursor.js#L10-L20`.

```javascript
import { useEffect, useRef } from '@wordpress/element';

export const useRateLimitedCursor = (cb, intervalMs = 2000, deps = []) => {
	const lastAtRef = useRef(0);
	const timerRef = useRef(null);

	useEffect(() => {
		const schedule = () => {
			clearTimeout(timerRef.current);

			const now = Date.now();
			const wait = Math.max(0, lastAtRef.current + intervalMs - now);

			const run = () => {
				lastAtRef.current = Date.now();
				const hasMore = cb();
				if (hasMore) schedule();
			};

			if (wait === 0) run();
			else timerRef.current = setTimeout(run, wait);
		};

		schedule();

		return () => {
			clearTimeout(timerRef.current);
			timerRef.current = null;
		};
	}, [cb, intervalMs, ...deps]);
};

```
