本页还没有译文
本页 26 段还没译成Português (BR),下面显示的是英文原文。TkDodo's Blog
还没翻译译自英文(tanstack.com)本页 26 段都还没译
React Query maintainer TkDodo has a series of blog posts about using and working with the library. Some articles show general best practices, but most have an opinionated point of view.
#1: Practical React Query
An advanced introduction to React Query, showing practical tips that go beyond the docs. It covers explaining the defaults (
staleTimevs.cacheTime), concepts like keeping server and client state separate, handling dependencies and creating custom hooks, as well as outlining why theenabledoption is very powerful. Read more...
#2: React Query Data Transformations
Learn the possibilities to perform the quite common and important task of transforming your data with React Query. From transforming in the
queryFnto using theselectoption, this article outlines the pros and cons of all the different approaches. Read more...
#3: React Query Render Optimizations
Let's take a look at what you can do when your component re-renders too often when using React Query. The library is already pretty optimized, but there are still some opt-in features (like
tracked queries) that you can use to avoid theisFetchingtransition. We're also looking into whatstructural sharingrefers to. Read more...
#4: Status Checks in React Query
We usually check for
isLoadingfirst before checking forisError, but sometimes, checking ifdatais available should be the first thing to do. This article shows how the wrong status check order can negatively impact user experience. Read more...
#5: Testing React Query
The docs already cover pretty well what you need to do to get started when testing React Query. This article shows some additional tips (like turning off
retriesor silencing theconsole) you might want to follow when testing custom hooks or components using them. It also links to an example repository with tests for success and error states, powered bymock-service-worker. Read more...
#6: React Query and TypeScript
Since React Query is written in TypeScript, it has great support for it. This blog post explains the various Generics, how you can leverage type inference to avoid having to explicitly type
useQueryand friends, what to do withunknownerrors, how type narrowing works and more! Read more...
#7: Using WebSockets with React Query
A step-by-step guide on how to make real-time notifications work with React Query, with either event-based subscriptions or pushing full data directly to the client. Applicable to anything from the browser native WebSocket API over Firebase and even GraphQL subscriptions. Read more...
#8: Effective React Query Keys
Most examples just use a simple String or Array Query Key, but how do you organize your keys effectively once your app grows past a todo list? This article shows how co-location and Query Key Factories can make life easier. Read more...
#9: Placeholder and Initial Data in React Query
Placeholder and Initial Data are two similar yet different concepts for synchronously showing data instead of a loading spinner to improve an application's UX. This blog post compares the two and outlines the scenarios where each one shines. Read more...
#10: React Query as a State Manager
React Query doesn't fetch any data for you - it's a data synchronization tool that excels when used for server state. This article has everything you need to know to make React Query your single source of truth state manager for your async state. You'll learn how to let React Query do it's magic and why customizing
staleTimemight be all you need. Read more...
#11: React Query Error Handling
Handling errors is an integral part of working with asynchronous data, especially data fetching. We have to face it: Not all requests will be successful, and not all Promises will be fulfilled. This blog post describes various ways of coping with errors in React Query, such as the error property, using Error Boundaries or onError callbacks, so that you can prepare your application for the cases when "Something went wrong". Read more...
#12: Mastering Mutations in React Query
Mutations are the important, second part necessary to work with server data - for situations where you need to update it. This blog post covers what mutations are and how they are different from queries. You'll learn the difference between
mutateandmutateAsyncas well as how you can tie queries and mutations together. Read more...