I know the regular refetching of the data in useQuery
const fetchData = async()=>{...}
// it starts fetching data from backend with this line of code
const {status, data, error, refetch } = useQuery(
myKey,
fetchData(),
{
enabled: false,
}
);
const onClick = () => { refetch() }
I know this refetches data (makes an API call) everytime the onClick function is called. I only want the API call to be made if the data is stale like the when the useQuery function is called. Is there a way to do that ?
2
Answers
Check if the data is stale and refetch accordingly.
Judging from this, you are likely looking for lazy queries. It’s important that you make the entered search string part of your queryKey.
With this, you don’t need refetch() at all.