Skip to main content
The @amank-root/better-auth-razorpay/react package exposes TanStack Query hooks for subscriptions, payments, orders, refunds, invoices, and more. Every hook expects an authClient created with the Razorpay client plugin, and they all run inside a QueryClientProvider.

Install peer dependencies

The React hooks require @tanstack/react-query and react as peer dependencies. Install them alongside the plugin if you haven’t already.

Wrap your app with QueryClientProvider

Create a QueryClient and wrap your application tree so hooks can cache and invalidate data.
app/providers.tsx
app/layout.tsx

Pass the auth client to every hook

All hooks take your authClient as the first argument. Create it with the Razorpay client plugin and pass it through your app, or import it from a shared module.
lib/auth-client.ts
components/billing.tsx

Query and mutation options

Query hooks accept an options object that can include queryOptions for TanStack Query’s useQuery. Mutation hooks accept mutationOptions for useMutation. You can set staleTime, refetchInterval, onSuccess, onError, and any other standard TanStack Query option.

Query keys

The package exports razorpayQueryKeys so you can invalidate or prefetch data manually.

Invalidation example

After a successful mutation, invalidate related queries so the UI refreshes automatically.
All hooks are client-only. In Next.js App Router, add "use client" at the top of any file that imports from @amank-root/better-auth-razorpay/react. If you need server-rendered data, fetch it in a Server Component and pass it down as props.