1. Which is best described as server state?
- The text typed in a search box
- Whether a modal is open
- A list of orders fetched from an API that may become stale
- A theme preference that never leaves the browser
जवाब देखें
जवाब: A list of orders fetched from an API that may become stale
Server state is a cache of data owned elsewhere, so it needs fetching, invalidation and refetching.
पाठ: Local, Server and Global Client State
2. For data fetched from a REST API with caching and refetch needs, what is usually the best fit?
- A server-cache library such as TanStack Query or RTK Query
- A hand-written Redux reducer for every endpoint
- React Context with useState
- localStorage
जवाब देखें
जवाब: A server-cache library such as TanStack Query or RTK Query
Server-cache libraries handle loading flags, deduplication, staleness and invalidation for you.
पाठ: When You Need a Store