Skip to main content

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 with SmartbillsProvider and a React Query QueryClientProvider:
The 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 useQuery or useInfiniteQuery for read operations. They return the standard React Query result object with data, isLoading, error, refetch, and pagination helpers.
  • Mutation hooks use useMutation for write operations. They return mutate / mutateAsync functions and automatically invalidate related cache entries on success.
This means you get all of React Query’s built-in features for free: background refetching, stale-while-revalidate, optimistic updates, infinite scrolling, and devtools support.

Hook Patterns

Query Hooks (read data)

Query hooks use useQuery or useInfiniteQuery under the hood. They return the standard React Query result object:

Mutation Hooks (write data)

Mutation hooks use useMutation and automatically invalidate related queries on success:

Automatic Cache Invalidation

When a mutation succeeds, the SDK automatically invalidates related queries. For example:
  • useCreateExpenseReport invalidates all expense report list queries
  • useUpdateExpense invalidates expense list queries
  • useApproveApprobation invalidates both approbation and expense report queries
This means your UI stays in sync without manual refetching.

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 a usePresignedUpload 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

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