Query Adapters
query() and mutation() are a thin surface over a
cache. Two caches can sit underneath. The default one has no dependencies; the
other is TanStack Query.
Your component code is identical either way, so this is a one-line decision you can change later.
The difference
basic (default) |
tanstack |
|
|---|---|---|
| Dependencies | None | @tanstack/query-core, ~15KB |
| Caching, stale-while-revalidate, invalidation | Yes | Yes |
| Retries, request cancellation, refetch on window focus | No | Yes |
| Infinite queries, DevTools | No | Yes |
Start with basic. Switch when a flaky network makes you want
retries, or when you want the TanStack DevTools.
Choosing one
source
// jaf.config.js
export default {
query: {
adapter: 'basic' // Default: zero dependencies
// adapter: 'tanstack' // TanStack Query
}
}
For tanstack, install @tanstack/query-core first.
Nothing else changes: every existing query() and
mutation() call keeps working.
Defaults for every query
source
// In your entry file, once
import { configureQuery } from 'jafjs/query'
configureQuery({
baseURL: '/api', // prepended to relative URLs
defaults: {
staleTime: 30000, // fresh for 30s
cacheTime: 300000, // keep unused data for 5min
refetchOnMount: true
}
})