Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Extracting queryFn from query key store #77

Open
linardsblk opened this issue Aug 21, 2023 · 0 comments
Open

Extracting queryFn from query key store #77

linardsblk opened this issue Aug 21, 2023 · 0 comments

Comments

@linardsblk
Copy link

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;
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant