Skip to content

Instantly share code, notes, and snippets.

@jimkeller
Created October 14, 2022 01:39
Show Gist options
  • Save jimkeller/2026c14ecd4e1028d56b0a21652b1e8c to your computer and use it in GitHub Desktop.
Save jimkeller/2026c14ecd4e1028d56b0a21652b1e8c to your computer and use it in GitHub Desktop.
react-query example for temporarily disabled query
/*
* 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