Use Axios when you want clean request code, use Fetch when you want zero dependencies, and use React Query when server data must stay cached, synced, and easy to refresh. React does not care which one you pick. The real choice is about error handling, caching, retries, loading states, and team habits. Fetch has been broadly available in browsers since March 2017 [source: MDN].
TLDR: For a small contact form, Fetch is enough. For an app with auth headers, interceptors, and repeated API calls, Axios is usually faster to work with. For a product dashboard with 12 API endpoints and 10,000 daily users, React Query can cut repeated loading states and reduce duplicate requests, especially when users switch tabs or return to the page. Example: use Axios to call /api/orders, then let React Query cache that result for 60 seconds.
Axios in React: practical and clean
Axios is a popular HTTP client because it makes common API work feel less annoying. JSON parsing is automatic. Request cancellation is supported. Errors are easier to read than raw Fetch responses. It also has interceptors, which are useful for auth tokens and logging.
Here is a simple Axios request in React:
import axios from "axios";
import { useEffect, useState } from "react";
function Users() {
const [users, setUsers] = useState([]);
const [error, setError] = useState("");
useEffect(() => {
axios.get("/api/users")
.then(res => setUsers(res.data))
.catch(err => setError(err.message));
}, []);
if (error) return <p>Failed: {error}</p>;
return users.map(user => <p key={user.id}>{user.name}</p>);
}
Best use case: Axios fits well in business apps where every request needs a token, base URL, timeout, and standard error handling.
const api = axios.create({
baseURL: "https://example.com/api",
timeout: 8000,
headers: { Authorization: `Bearer ${token}` }
});
The catch is that Axios does not solve caching by itself. You still need to manage loading, stale data, retries, and refetching. That gets old quickly in larger React apps.
Fetch in React: simple, built in, but rough at the edges
Fetch is built into the browser. No package install. No bundle weight. That is a real benefit for small projects, widgets, and pages with one or two API calls.
import { useEffect, useState } from "react";
function Users() {
const [users, setUsers] = useState([]);
const [error, setError] = useState("");
useEffect(() => {
fetch("/api/users")
.then(res => {
if (!res.ok) throw new Error("Request failed");
return res.json();
})
.then(data => setUsers(data))
.catch(err => setError(err.message));
}, []);
if (error) return <p>Failed: {error}</p>;
return users.map(user => <p key={user.id}>{user.name}</p>);
}
Fetch looks fine here, but real apps add friction. You must check res.ok yourself. You must parse JSON yourself. Timeouts need extra code. Interceptors are not built in. Honestly, it feels like writing the same helper function every week.
Best use case: Fetch is good for small React apps, static sites, demos, and teams that want fewer dependencies.
React Query: better server state
React Query, now part of TanStack Query, is not a replacement for Axios or Fetch. It manages server state. You still use Axios or Fetch inside the query function. React Query then handles caching, background refresh, retries, loading flags, and stale data rules. Its docs describe features such as caching, request deduping, and background updates [source: TanStack].
import axios from "axios";
import { useQuery } from "@tanstack/react-query";
function Users() {
const { data, isLoading, isError, error } = useQuery({
queryKey: ["users"],
queryFn: async () => {
const res = await axios.get("/api/users");
return res.data;
},
staleTime: 60000
});
if (isLoading) return <p>Loading...</p>;
if (isError) return <p>Failed: {error.message}</p>;
return data.map(user => <p key={user.id}>{user.name}</p>);
}
This is where React Query earns its place. If users open a profile page, leave it, then return 20 seconds later, the cached data can show instantly. The app can refresh in the background. That feels faster and avoids needless spinners.
Best use case: React Query is best for dashboards, admin panels, SaaS apps, ecommerce accounts, reports, and any screen where data is reused.
Axios vs Fetch vs React Query
- Use Fetch for simple reads, tiny apps, and cases where dependency count matters.
- Use Axios when you need cleaner errors, default config, auth headers, uploads, timeouts, and interceptors.
- Use React Query with Axios when the app has repeated server data, caching needs, retries, pagination, or background updates.
- Avoid manual
useEffectfetching everywhere in large apps. Expect to waste time fixing duplicate requests and stale UI bugs.
A practical recommendation
For most serious React apps, the safest setup is Axios plus React Query. Axios handles the HTTP layer. React Query handles the state layer. This split is clean and easy to test.
const fetchOrders = async () => {
const res = await api.get("/orders");
return res.data;
};
const { data, isLoading } = useQuery({
queryKey: ["orders"],
queryFn: fetchOrders,
staleTime: 30000
});
For a single form submission, do not overbuild it. Fetch is fine. For five protected endpoints, Axios starts to pay off. For a full dashboard with filters, tabs, pagination, and refresh rules, React Query is the better tool.
Final verdict
Fetch is the baseline. Axios is the cleaner HTTP client. React Query is the missing server state manager. Pick based on the cost of mistakes. If one failed request is no big deal, keep it simple. If stale data can confuse users or hurt revenue, use React Query with a solid Axios client. That choice keeps React code smaller, clearer, and easier to trust.