Skip to main content

Advanced Usage

This guide covers advanced SDK features for power users.

Custom Endpoint

The hooks and query functions call /api/daocafe on the current origin (see Server Handler). Point them somewhere else if your handler lives on another path or host.

Changing the Default Endpoint

Creating a Custom Client

Modifying Default Client Headers


Refreshing After Transactions

The server answers from a cache that re-syncs every 15 seconds. After a transaction is mined, use refreshDaoCafe so the user sees their change right away:
If you invalidate specific query keys yourself, call markFresh() before invalidating.

Cache Invalidation

When using React hooks with TanStack Query, you can invalidate cached data to trigger refetches.

Basic Invalidation

Targeted Invalidation

Invalidate only specific queries for better performance:

Query Key Reference


Error Handling

With React Hooks

TanStack Query provides built-in error handling:

With Query Functions

Use try/catch for promise-based functions:

Common Error Types


Retry Configuration

Configure TanStack Query’s retry behavior:

Tree-Shaking

The SDK is designed for optimal bundle sizes. Only import what you need:

Bundle Size Tips

  1. Import specific hooks instead of entire modules
  2. Use type imports for TypeScript types
  3. React hooks are optional - if you don’t import them, they’re not bundled

Pagination

All list queries support cursor-based pagination:

Infinite Scroll with TanStack Query


Server-Side Rendering

For Next.js or other SSR frameworks, prefetch data on the server: