Sitemap
Sofia Marques

Sofia Marques

React rookie logging sprint-sized lessons on fast, accessible UI. Cat person. Disney adult.

Why data fetching is a UI problem (not an API problem)

5 min readMar 3, 2026

--

For a long time, I viewed data fetching as an API problem. You call an endpoint, get JSON back, and render it. That mental model felt clean and reassuring. It also made me think that once the API call worked, my job was basically done.

In real applications, that framing quickly showed its limits. The issue was not the API itself, but everything that happened before, after, and in between the arrival of the data.

Data fetching includes how the interface behaves when data is missing, partial, stale, or wrong. This behavior belongs to the UI.

Press enter or click to view image in full size

The model that looks right and fails quietly

Early in my React learning, my components followed a familiar rhythm. Fetch on mount; render when the data arrives. When the data did not exist yet, I returned a spinner and moved on.

useEffect(() => {
fetchUser().then(setUser);
}, []);

Somewhere else in the component, loading was handled almost casually.

if (!user) {
return <Spinner />;
}

That single line hides several design decisions. What does the user see while waiting? Does the layout jump when content appears? Is the spinner replacing a meaningful structure, or is it merely reserving space for it?

Once I noticed this, loading stopped feeling like a technical detail and started feeling like a user-facing state. Making the state explicit helped clarify that shift.

type RequestState<T> =
| { status: "loading" }
| { status: "success"; data: T }
| { status: "error"; error: Error };

With that structure in place, the UI is forced to be intentional, even in simple cases where I would normally reach for a boolean and move on. This is a straightforward case of conditional rendering in React.

if (state.status === "loading") {
return <ProfileSkeleton />;
}

if (state.status === "error") {
return <ProfileError />;
}

return <UserProfile data={state.data} />;

At that point, loading stopped being a boolean and became a design problem. Whether a skeleton mirrors the final layout or previously loaded data remains visible, those decisions do not come from the API.

Press enter or click to view image in full size

Empty data is still a valid state

Another early assumption I had was that empty data meant something had gone wrong. An empty array felt like a failure.

In reality, empty data often means the system is working as intended. A new account, a cleared inbox, or a filter with no matching results can all produce empty responses.

The API has done its job. The UI now has to explain what that absence means by setting expectations and clarifying what the user is looking at and what their next step might be.

Errors deserve design attention

Errors are not rare edge cases. I learned this the hard way in a sprint where a token expired mid-session, and the UI just froze.

Get Sofia Marques’s stories in your inbox

Join Medium for free to get updates from this writer.

When error states are not designed intentionally, users are left with frozen spinners or broken layouts. A clear error message with calm language and a visible recovery path feels far more trustworthy.

if (state.status === "error") {
return (
<ErrorState
message="We could not load your profile."
onRetry={refetch}
/>
);
}

The most important choices here are about tone, context, and whether the user can recover without losing their place. Those decisions live entirely in the UI layer. A retry button is useful, but clarity and reassurance usually matter more.

Press enter or click to view image in full size

Transitions shape the experience

One of the more subtle lessons was realizing that correct data does not guarantee a good experience. The way the UI moves between states matters just as much.

I have built pages where refetches caused the screen to flash, collapse, or jump, even though the data was correct. Keeping previous data visible during updates reduced that instability.

Tools like React Query make this easier, but the design decision exists regardless of library choice.

const { data, isFetching } = useQuery(
["todos"],
fetchTodos,
{ keepPreviousData: true }
);

With this approach, the interface remains visually stable while new data loads in the background. Libraries that support keeping previous data during refetches make this pattern easier to implement.

Partial data is often enough

“Fetch then render” assumes completeness. Real interfaces rarely operate that way.

Some information matters immediately, while other parts can arrive later. Showing key content first can make an application feel responsive even when the network is slow.

Rather than waiting for everything to be ready, React Suspense allows the UI to be honest about what it has, what it is waiting for, and what the user should see first.

<UserHeader user={user} />
<Suspense fallback={<PostsSkeleton />}>
<UserPosts userId={user.id} />
</Suspense>

Here, the UI is making a prioritization decision. The user’s identity and surrounding context are rendered immediately, while the posts are treated as secondary and allowed to load later. The API simply provides data; it does not understand hierarchy, focus, or what the user needs first. React Suspense makes this kind of partial rendering explicit.

Press enter or click to view image in full size

Why “fetch then render” is not enough

“Fetch then render” answers how data arrives. It does not address what the user experiences while waiting, what happens when something fails, or how the interface behaves as data changes.

Those questions are answered through layout, transitions, copy, and state modeling. They are UI decisions layered on top of data access.

The API provides the ingredients. The UI decides how they are presented.

A practical takeaway

Treat data fetching as an integral part of interface design, not just a technical step.

When loading, empty, error, and partial states are designed with intention, the application feels calmer and more reliable. Users may not consciously notice why, but they feel the difference.

That shift, from treating data fetching as an API concern to treating it as a UI responsibility, changed how I build React interfaces more than any specific library or hook.

--

--

Sofia Marques
Sofia Marques

Written by Sofia Marques

React rookie logging sprint-sized lessons on fast, accessible UI. Cat person. Disney adult.