A
A
Andrey Okhotnikov2020-05-20 13:41:55
React
Andrey Okhotnikov, 2020-05-20 13:41:55

Repeat query in graphql on component initialization?

I have a query that should only fire when the PAGE state changes.

const { data, error, loading, refetch } = useCatalogPageQuery({
    variables: { page }
  });


But 2 requests are always executed - the first when the component is initialized, and the second when the page is changed, how to make it work only when the page changes?

Tried like this, same situation

useEffect(() => {
    refetch()
  }, [page]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Okhotnikov, 2020-05-20
@tsepen

Answer - you need to set the skip parameter

const { data, error, loading, refetch } = useCatalogPageQuery({
    variables: { page },
    skip: true
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question