Introduction
The@smartbills/react-hooks SDK provides a comprehensive set of React hooks built on top of TanStack React Query. Each hook wraps a Smartbills API endpoint with automatic caching, pagination, cache invalidation, and optimistic updates.
This SDK requires
@smartbills/sdk (the core JS client) and @tanstack/react-query as peer dependencies.Installation
Provider Setup
Wrap your application withSmartbillsProvider and a React Query QueryClientProvider:
SmartbillsProvider makes the Smartbills client available to all hooks via React context. The businessId scopes all API calls to the specified business.
How Hooks Work
Under the hood, every hook maps to a React Query primitive:- Query hooks use
useQueryoruseInfiniteQueryfor read operations. They return the standard React Query result object withdata,isLoading,error,refetch, and pagination helpers. - Mutation hooks use
useMutationfor write operations. They returnmutate/mutateAsyncfunctions and automatically invalidate related cache entries on success.
Hook Patterns
Query Hooks (read data)
Query hooks useuseQuery or useInfiniteQuery under the hood. They return the standard React Query result object:
Mutation Hooks (write data)
Mutation hooks useuseMutation and automatically invalidate related queries on success:
Automatic Cache Invalidation
When a mutation succeeds, the SDK automatically invalidates related queries. For example:useCreateExpenseReportinvalidates all expense report list queriesuseUpdateExpenseinvalidates expense list queriesuseApproveApprobationinvalidates both approbation and expense report queries
Available Domains
The SDK provides hooks for 37 domains covering the full Smartbills platform:Expenses
List, upload, update, delete, split, bulk operations, export
Expense Reports
CRUD, submit, approve, reject, recall, reimburse, comment
Approvals
Pending, approved, rejected, reimburse, request changes
Bills
CRUD, approve, schedule payment, mark paid, cancel, bulk
Invoices
CRUD, send, void, mark paid, duplicate, summary
Vendors
CRUD, merge, bulk delete, logo upload
Employees
List and manage employee records
Categories
List and manage expense categories
Departments
List and manage departments
Presigned Uploads
The SDK includes ausePresignedUpload hook that handles the full S3 presigned upload flow:
React Query Options
Every hook accepts standard React Query options as the last parameter, giving you full control over caching behavior:Authentication Flow
TheSmartbillsProvider accepts a pre-configured SmartbillsClient instance. For applications where the access token changes (for example, after user login), update the client instance and React Query will automatically refetch:
Next Steps
Hooks Reference
Complete reference table of all 100+ hooks organized by domain