Is there a way to clear/reset the data to an empty array from a useQuery hook? #2491
Unanswered
RyanPayso13
asked this question in
Q&A
Replies: 2 comments 1 reply
-
One way is your could move the search term length check into useQuery hook's function. Since all that the function needs to do is return a promise, in case of empty search term it can resolve to Promise with empty array. Then you don't need to use
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I answered on stackoverflow: https://stackoverflow.com/questions/68491200/reset-a-react-query-usequery-hook-to-clear-data-on-the-rendered-page/68498963#68498963 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am writing a search component which uses react query to fetch the data.
Which I then import in my component, and refetch the data when the user enters a search term:
There is a requirement to not show any data when there is nothing in the
searchTerm
i.e.searchTerm
is an empty string.However, the API returns all results when a search term is not passed to it and I cannot alter that behaviour.
Is there a way to reset
useQuery
hook to returndata
as an empty array?Beta Was this translation helpful? Give feedback.
All reactions