NextJS and react-query

1.1k views Asked by At

enter image description here

As you can see here, I used useQuery() but I only want it to fetch once. Not sure if it is NextJS problem or react-query problem.

2

There are 2 answers

0
g1r0 On

react-query does query retries out of the box. See the docs here. It is possible to disable it, passing { retry: false } as options to useQuery() hook.

0
Rafael Zerbini On

Without code is hard to evaluate, but this works fines for me in NextJS. Probably the problem is where you're calling useQuery hook

function App (){
  const { loading, error, data: { listCourses: courses } = {} } = useQuery(
    listCourses(),
    {
      variables: { type: "online" },
    }
  );

  return (
    <Layout>
      {something}
    </Layout>
  );
};