Recent Entries 6
- principle moderate 124d agoTanStack Query — staleTime vs gcTime (cacheTime) explainedDevelopers confuse staleTime and gcTime (formerly cacheTime) and set them incorrectly. Setting staleTime too low causes excessive refetches; setting gcTime too low destroys cache between navigations.
- pattern tip 124d agoTanStack Query — prefetching data before navigationWhen a user navigates to a detail page, useQuery starts fetching only after the component mounts, causing a loading flash. Prefetching loads data into the cache before navigation so the page renders immediately.
- pattern tip 124d agoTanStack Query — infinite scroll with useInfiniteQueryPaginated lists loaded with separate useQuery calls per page require manual state for the current page and accumulated data. useInfiniteQuery handles accumulation, page tracking, and the 'load more' trigger automatically.
- pattern moderate 124d agoTanStack Query — optimistic updates with rollback on errorAfter a mutation the UI waits for the server response before reflecting changes. For fast actions (like toggling a like button), this creates noticeable lag. Optimistic updates apply the change immediately and roll back if the server rejects it.
- pattern moderate 124d agoTanStack Query — cache invalidation and refetching after mutationsAfter a create/update/delete mutation, the cache still holds the old data. Without explicit invalidation, the UI shows stale data until the cache expires.
- pattern tip 124d agoTanStack Query basics — useQuery for server stateManaging server data in React requires loading state, error state, caching, and refetch logic in every component. Writing this manually with useEffect is error-prone and results in duplicated, inconsistent code.