TanStackT
TanStack16mo ago
7 replies
foolish-indigo

RQ architecture suggestions

I'm having a bit of a dillema on how to structure my queries. I really love using queryOptions as it lets me override any of the options.

export const getProjectQueryOpts = (
  variables: GetProjectRequest,
  init: RequestInit = {},
) => {
  const queryKey = [
    "projects",
    variables.params.pid
  ] as const

  return queryOptions({
    queryKey,
    queryFn: () => getProject(variables, init)
  });
};


  const project = useQuery({
    ...getProjectQueryOpts({
      params: {
        pid
      }
    }),
    staleTime: Infinity,
  });


The problem with this approach is that you cant effectively use skipToken because I want to keep the
variables
as required. The only solution is to make the variables optional in which case I can make typescript happy with the usage, and then handle the skipToken within the getProjectQueryOpts - but it feels weird to do so....
Was this page helpful?