Overview
ThehookAPI() method creates a public query and mutation that can be used with the useRateLimit React hook. It returns two functions: getRateLimit for fetching current rate limit values, and getServerTime for client/server time synchronization.
Method Signature
Type Definitions
Parameters
string
required
The name of the rate limit to expose. Must match a rate limit defined in your
RateLimiter constructor, unless you provide an inline config.HookOptions
Optional configuration for the hook API.
Return Value
QueryFunction
A Convex public query that returns the current rate limit value and metadata.Arguments:Returns:
MutationFunction
A Convex public mutation that returns the current server time (
Date.now()). Used by useRateLimit to synchronize client and server clocks.Arguments: NoneReturns: number - Server timestamp in millisecondsUsage Patterns
Pattern 1: Server-Side Key (Recommended)
Pattern 2: Static Key (Global Rate Limit)
Pattern 3: Client-Provided Key (Use with Caution)
Complete Setup Example
Server Setup
Client Setup
Key Function Patterns
Authentication-Based
IP-Based (requires custom auth setup)
Multi-Tenant with Validation
Related
- useRateLimit - React hook that uses this API
- React Hooks Guide - Complete integration examples
- getValue() - Alternative server-side value fetching