Lesson 29 of 80
Data you fetched from somewhere else isn't the same kind of thing as a toggle's on/off flag — it can go stale, be shared across components, and need retrying. Treating both as 'just useState' is where a lot of real app complexity comes from.
13 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
What makes server state fundamentally different from client state like a form input's value?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Client state is state your app fully owns and controls — a form's current input, whether a menu is open, the selected tab. Server state is a local cache of data that actually lives somewhere else — an API, a database — which means your copy of it can become stale at any moment without your app doing anything.
// The naive approach: server state handled like client state
function Profile({ userId }) {
const [user, setUser] = useState(null);
useEffect(() => {
fetch(`/api/users/${userId}`).then((r) => r.json()).then(setUser);
}, [userId]);
// no loading state, no error state, no cache, no re-fetch on window refocus,
// no dedup if another component fetches the same user at the same time...
}
This works for the simplest case, but server state has needs client state never does: loading/error states, caching, deduplication of identical in-flight requests, background re-fetching, and cache invalidation after a mutation. Writing all of that by hand in every component that fetches data is exactly the problem dedicated data-fetching libraries (React Query, SWR, RTK Query) exist to solve.
Client state: theme, form input, isOpen — lives only in this browser tab, owned by useState.
useEffect version above doesn't."How would you handle data fetching in a large React app?" is really asking whether you distinguish server state from client state — recognizing that "just useState + useEffect" doesn't scale to caching, staleness, and shared requests is the actual signal.