Example React program using TanStack Query.
Powerful asynchronous state management for TS/JS, React, Solid, Vue and Svelte
This is my own "learn by doing" project for learning TanStack Query. The program is similar to the react/basic
official
example in the TanStack Query codebase.
Follow these instructions to build and serve the program:
- Pre-requisite: Node.js
- I used version 20.11.0
- Install the dependencies
-
npm install
-
- Serve the content (and build continuously)
-
npm start
-
- Open the browser
- Open http://[::1]:8000
- Open the browser dev tools, and you'll see that the program does not suffer from double
fetch
requests even though<React.StrictMode>
is enabled. You'll notice the extra renders, but only onefetch
request. The logs look something like the following. -
[News] Render function invoked. [News] Render function invoked. [queryFn] invoked. [News] Render function invoked. [News] Render function invoked.
General clean-ups, todos and things I wish to implement for this project:
- DONE Implement
- DONE (very nice, TanStack Query delivering excellently on its promise) How to implement "refresh this data"? If I had a refresh button, do you call some method to invalidate the cache for that key or something?