1. Introduction: What is TanStack Query?

TanStack Query (formerly React Query) is a framework-agnostic state management library designed specifically to manage Server State—handling data fetching, caching, background updating, and cache invalidation.

2. Server State vs. Client State & The Memory Reality

Client State: Owned and controlled entirely by the browser (e.g., isModalOpen, selected UI theme).

Server State: Owned by the remote backend database (e.g., user profiles, posts, cart items). The browser only holds a read-only temporary snapshot.