T
TanStack3y ago
flat-fuchsia

Should React-Query only be used for api calls?

I'm working on a project involving connecting to a bluetooth device, which is an async process. I've opted to use react query to get the same state management that I'd expect from an API call, but I'm getting some pushback from the other devs on my team saying it should just be used for API management. Curious what everyone else's thoughts were because I always operated under the thought that react-query is state management for anything async, not just APIs
4 Replies
variable-lime
variable-lime3y ago
Hi. Definitely. We do use it for both api calls and in-memory async process. For ex, we do heavy data transformation in async process that we keep in memory. Not API call in this case but still the same comfort to handle loading/error etc.
variable-lime
variable-lime3y ago
You can use React Query for slow computation, not just API | Swizec...
You can use the ergonomics of React Query for any slow operation and it's wonderful.
exotic-emerald
exotic-emerald3y ago
Yeah, it's definitely not designed solely for managing network requests. It's designed for any asynchronous state 👍
ratty-blush
ratty-blush3y ago
Just to add to this, and maybe another explanation that might made sense, React-Query is not an API Call tool. It doesn't perform the API calls themselves (for our application we use Axios for this). React Query is a server state management tool primarily, but as lots of others are saying it really can be for anything that returns a promise, including working with bluetooth stuff, or just any process in your app that might be asynchronous. And hey, if it works for you, it works!

Did you find this page helpful?