T
TanStack12mo ago
other-emerald

Updating react query cache frequently without spamming my backend

Hello, I'm working on an app that requires to consume a single cache entry from different components at the same time. This entry is initially populated from a query (useGraph) and then is updated when an specific mutation is used (useUpdateNode). Because of a new feature I'm building I need to frequently update the useGraph query cache optimistically (useUpdateNode mutation is called when a text input onChange event is triggered), and it must be reflected instantly in the other components that consume the query. What I'm looking for is a way to debounce the execution of the fetch function, without debouncing the execution of the mutation itself as it would also debounce the optimistic update. Here is an approach for a similar use case as mine: https://github.com/TanStack/query/issues/293#issuecomment-1480549534, but I'm wondering if is there a less complicated solution to this.
GitHub
Cannot debounce API calls · Issue #293 · TanStack/query
I am trying to use this for a search component, like: const { status, data, error, isFetching } = useQuery( searchQuery && ['results', searchQuery], getSearchAsync, ); I would like ...
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?