redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

RTKQ: useLazyQuery + refetchOnMountOrArgChange

Open sucat opened this issue 2 years ago • 0 comments

Hey! useQuery hook accepts refetchOnMountOrArgChange option. I find it very helpful when I need to refetch the data from the API after some time passed.

I'd like to achieve exact same results but with useLazyQuery:

  1. There is a component rendered with button.
  2. When button is clicked - call trigger from useLazyQuery.
  3. When the button is clicked again within 5s - serve the data from cache
  4. When the button is clicked after 5s - make API request

Is it currently achievable? I tried many things but couldn't get it working like that with useLazyQuery hook.

Thanks!

sucat avatar Nov 20 '23 20:11 sucat