Overview
TheuseRateLimit hook provides real-time rate limit information in your React components. It monitors the current rate limit status and automatically updates when capacity changes, allowing you to show users when they can retry an action.
Function Signature
Type Definitions
Parameters
GetRateLimitValueQuery
required
The query function returned by
rateLimiter.hookAPI().getRateLimit. This query retrieves the current rate limit value from the server.UseRateLimitOptions
Optional configuration object for the hook.
Return Value
object | undefined
The current rate limit status.
undefined while loading.When ok: true:When ok: false:function
A function to manually check the rate limit at a specific time or for a different token count.Signature:
(ts?: number, count?: number) => CheckResult | undefinedReturns CheckResult | undefined:Usage Example
Basic React Component
With Manual Checking
Time Synchronization
The hook usesgetServerTimeMutation to synchronize the client and server clocks. This is highly recommended because:
- Client clocks can be inaccurate or intentionally set incorrectly
- The rate limit calculations happen server-side using server time
- Without synchronization,
retryAtvalues may be incorrect
How It Works
Server Setup
ThegetServerTime mutation is automatically included when you use hookAPI():
Advanced Patterns
See React Hooks Guide for more examples including:- Displaying countdown timers
- Optimistic UI updates
- Multi-token operations
- Custom retry strategies
Related
- hookAPI() - Set up server-side queries for the hook
- React Hooks Guide - Advanced usage patterns
- getValue() - Direct value fetching