What's different with HTTP Cache and React Query ?
My backend engineer ask me this question. I don't know how to reply. anyone can give me a favor, what's the benefit about React Query?
2 Replies
xenial-black•3y ago
As part of the responses from your server you can include headers that tell the browser itself how long the fetched data is valid before it expires. React query is a layer on top of that and is useful for state management of requests e.g. application level caching and having the UI respond to the availability of the data e.g. if it's loading etc.
The way that you fetch data is dependent on what type of data it is and when you expect it to update.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
Cache-Control - HTTP | MDN
The Cache-Control HTTP header field holds directives (instructions) — in both requests and responses — that control caching in browsers and shared caches (e.g. Proxies, CDNs).
rare-sapphire•3y ago
react-query is not involved for the HTTP fetching part, you're still in control of that. SO react query doesn't add any http caching.