最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论