Skip to content

Extracting queryFn from query key store #77

@linardsblk

Description

@linardsblk

Hi. I was trying to implement queryKeyStore that I could use in Nextjs in both SSR and client-side. In order to prefetch, I need to call the defined function but it requires a parameter of type QueryFunctionContext.

Expected 1 arguments, but got 0.ts(2554)
types.d.ts(9, 108): An argument for 'context' was not provided.
const queryFn: (context: QueryFunctionContext<readonly ["administrators", "list", string], any>) => AdministratorDto[] | Promise<AdministratorDto[]>

Is there a good way to extract queryFn? I want to define by API once in the queryKeyStore then use it in all of my application. Here is the example.

const AdministratorsPage = () => {
  const { data: administrators } = useQuery(
    queryKeyStore.administrators.list(),
  );

  return (
    //...
  );
};


export const getServerSideProps = async () => {
  const queryClient = new QueryClient()


  const { queryKey, queryFn } = queryKeyStore.administrators.list();
  await queryClient.prefetchQuery(
    queryKey,
    queryFn,
  );

  return {
    props: {
      dehydratedState: dehydrate(queryClient),
    },
  }

export default AdministratorsPage;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions