admin 管理员组

文章数量: 1086019

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 ?

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 ?

Share Improve this question edited Jan 30, 2020 at 16:17 Edgar asked Jan 30, 2020 at 16:04 EdgarEdgar 6,86811 gold badges38 silver badges74 bronze badges 2
  • what do you mean about Repeated request ? – abdelhedi hlel Commented Jan 30, 2020 at 16:28
  • when the ponent is first built, the request is sent and the second time the request does not occur – Edgar Commented Jan 30, 2020 at 16:47
Add a ment  | 

1 Answer 1

Reset to default 6

When you use the useQuery hook, the query you provide is fetched when the ponent 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 ponent rerenders -- this would result in excessive requests and an infinite render loop.

本文标签: javascriptfetchPolicy option quotnocachequot does not work in useQueryStack Overflow