Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetchPolicy option: "no-cache" does not work in useQuery

this my code

const { loading, error, data } = useQuery(HeaderPage.query, {
    fetchPolicy: "no-cache"
  });

when i use fetchPolicy: "no-cache". Repeated request does not go.

What is the reason why only once a request is made ?

like image 788
Silicum Silium Avatar asked Apr 03 '26 00:04

Silicum Silium


1 Answers

When you use the useQuery hook, the query you provide is fetched when the component mounts. Whether it's fetched from the server or the cache will depend on your cache policy (and whether there's anything in the cache). After the query is initially fetched, it will only be fetched again if either 1) the options passed to the hook change or 2) you call the refetch function returned by the hook. The query will not be fired again just because the component rerenders -- this would result in excessive requests and an infinite render loop.

like image 109
Daniel Rearden Avatar answered Apr 04 '26 13:04

Daniel Rearden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!