const [page, setPage] = useState(1);const queryClient = useQueryClient();const { data, isPreviousData } = useQuery({queryKey: ['todos', page],queryFn: () => fetch(`/api/todos?page=${page}`).then(r => r.json()),keepPreviousData: true});// manual pre-fetch of next pageuseEffect(() => {queryClient.prefetchQuery({queryKey: ['todos', page + 1],queryFn: () => fetch(`/api/todos?page=${page + 1}`).then(r => r.json())});}, [page, data]);// manual delete + cache syncconst del = useMutation({mutationFn: id => fetch(`/api/todos/${id}`, { method: 'DELETE' }),onSuccess: () => queryClient.invalidateQueries(['todos'])});// manual add + cache syncconst add = useMutation({mutationFn: body => fetch('/api/todos', {method: 'POST', body: JSON.stringify(body)}),onSuccess: () => queryClient.invalidateQueries(['todos'])});
const todoList = (page, size) =>alova.Get('/api/todos', { params: { page, size } });const { loading, data, page, pageSize, pageCount, total } =usePagination(todoList);// auto paging · preload · add/remove sync
Client strategies
Built-in hooks that replace the boilerplate you would otherwise hand-write with React Query or axios.
Automatically manage paging data, data preloading, reduce unnecessary data refresh, improve fluency by 300%, and reduce coding difficulty by 50%
const todoList = (page, size) =>alova.Get('/todos', { params: { page, size } });const { loading, data, page, pageSize, pageCount, total } =usePagination(todoList);
send requests immediately by watching states changes, useful in tab switching and condition quering.
useWatcher(() => alova.Get(`/rewards/${activeKey}`),[activeKey],{debounce: [500, 0]})
Preload data to display view faster, or re-fetch data across components.
const { fetching, error, fetch } = useFetcher()fetch(alova.Get('/todo/1'))
Global interceptor that supports silent token refresh, as well as providing unified management of token-based login, logout, token assignment and token refresh.
const { onAuthRequired, onResponseRefreshToken } = createServerTokenAuthentication({refreshTokenOnError: {isExpired: res => res.status === 401,handler: async () => {const { token, refresh_token } = await refreshToken()localStorage.setItem('token', token)localStorage.setItem('refresh_token', refresh_token)}}})const alovaInstance = createAlova({beforeRequest: onAuthRequired(),responded: onResponseRefreshToken()})
Automatically manage form data, it allow you implement quickly various of forms.
Server strategies
Server-side control — retry, rate limiting, atomic requests and more — without adding middleware.
Using it on important requests can improve their stability.
const res = await retry(alova.Post('/api/order'), {retry: 3,backoff: {delay: 1000,multiplier: 2}})
Limit the request rate within a certain period of time.
const limit = createRateLimiter({points: 4,duration: 60 * 1000})const orderRes = await limit(alova.Get('/api/order'))
Guarantee request atomicity in multi-process environments with a distributed lock — no hand-written locking code.
import { atomize } from 'alova/server';// a distributed lock keeps the request atomicconst res = await atomize(alova.Get('/api/user'),{channel: 'user_lock',timeout: 5000})
Cross-component, zero wiring
Trigger and sync requests across any component — no prop drilling, no global store.
When should you NOT use alova?
Stick with React Query / axios when
- You only need simple CRUD + basic caching
- Your team already standardised on one of them
- The app is small and request logic is minimal
alova wins when
- You want 70% less request code out of the box
- Complex admin / BFF / cross-platform / server-side control
- You need built-in strategies (pagination, auth, retry, SSE…)
Request libs like fetch and axios make requests very simple, react-query and swr further reduce the template code of requests. But what alova aims to do is to provide extreme API consumption efficiency, eliminating almost all of your request work and achieving more efficient Client-Server data interaction.
I'm loving this library and slowly migrating my code from Axios to Alova.
Alova is really meticulous. When I read the documents, every point was a pain point and solved many problems.
The alovajs is nice. I plan to switch our products to alovajs uniformly



