How can i make the search button work with react query? #4555
-
I have the following code and it works. I have tried various ways to make it work: using the enabled, using the refetch, and it doesnt seem to work. So instead of pasting here the none working one, i decided to show you guys what I want to do. I cannot create a sandbox as its fetches to my docker postgres container.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I don't know why everyone keeps saying things like that. You can do it. You can change the query function. You don't have to use axios in there. It's fine to return some json from the queryFn that does NOT come from the network. If react-query is the problem, then the sandbox will show the problem even if you don't "fetch" in there... https://tkdodo.eu/blog/how-can-i#3-provide-a-minimal-reproducible-example |
Beta Was this translation helpful? Give feedback.
-
Here i got the example @TkDodo https://codesandbox.io/s/react-query-search-t9lk76 |
Beta Was this translation helpful? Give feedback.
-
all you are really missing is to add the https://codesandbox.io/s/react-query-search-forked-t1o496?file=/src/App.js I've also added Everything you use in the queryFn should be part of the queryKey. This is documented:
We even have an eslint rule that should catch this: |
Beta Was this translation helpful? Give feedback.
all you are really missing is to add the
query
to the queryKey:https://codesandbox.io/s/react-query-search-forked-t1o496?file=/src/App.js
I've also added
keepPreviousData
, but that is merely to avoid loading states between filters.Everything you use in the queryFn should be part of the queryKey. This is documented:
We even have an eslint rule that should catch this: