Created
October 14, 2022 01:39
-
-
Save jimkeller/2026c14ecd4e1028d56b0a21652b1e8c to your computer and use it in GitHub Desktop.
react-query example for temporarily disabled query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* call the useQuery hook, but leave the | |
* 'enabled' flag to false. Doing so prevents the query | |
* from running immediately on component mount. | |
*/ | |
const { data, refetch, isError, isRefetching } = useQuery( | |
['search_results', inputValue], | |
async () => { | |
return await axios.get(`/path/to/results/api/${inputValue}`).catch((err) => { //handle error here }) | |
}, | |
{ | |
refetchOnWindowFocus: false, | |
enabled: false //disable the query: | |
//this is how we keep it from running on component mount. | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment