function createRateLimitedValue<TValue>(value, initialOptions): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>>]
function createRateLimitedValue<TValue>(value, initialOptions): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>>]
Defined in: rate-limiter/createRateLimitedValue.ts:43
A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window. This hook uses Solid's createSignal internally to manage the rate-limited state.
Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
For smoother update patterns, consider:
Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
The hook returns a tuple containing:
For more direct control over rate limiting behavior without Solid state management, consider using the lower-level createRateLimiter hook instead.
• TValue
Accessor<TValue>
RateLimiterOptions<Setter<TValue>>
[Accessor<TValue>, SolidRateLimiter<Setter<TValue>>]
// Basic rate limiting - update at most 5 times per minute
const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
limit: 5,
window: 60000
});
// Use the rate-limited value
console.log(rateLimitedValue()); // Access the current rate-limited value
// Control the rate limiter
rateLimiter.reset(); // Reset the rate limit window
// Basic rate limiting - update at most 5 times per minute
const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
limit: 5,
window: 60000
});
// Use the rate-limited value
console.log(rateLimitedValue()); // Access the current rate-limited value
// Control the rate limiter
rateLimiter.reset(); // Reset the rate limit window
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.