Skip to main content

Overview

The useRateLimit 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 uses getServerTimeMutation to synchronize the client and server clocks. This is highly recommended because:
  1. Client clocks can be inaccurate or intentionally set incorrectly
  2. The rate limit calculations happen server-side using server time
  3. Without synchronization, retryAt values may be incorrect

How It Works

Server Setup

The getServerTime 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