tRPCttRPC
Powered by
.westsaid.
tRPC•3y ago•
1 reply
.westsaid

useInfinieQuery with initialData, Refetch only after second change of inputs

Hi everyone,

I have the problem as stated in the title. My code looks like the following:

  const queryInput = {
    locale,
    pageId: id,
    selectedFilterGuids: activeOptionsValues,
  };

  const { data, fetchNextPage, isFetchingNextPage } =
    trpc.epiApiRouter.artistLandingPage.useInfiniteQuery(queryInput, {
      ...reactQueryNoRefetch,
      getNextPageParam: (lastPage) => lastPage.lastPage + 1,
      initialData: () => ({ pageParams: [undefined], pages: [{ ...initialData }] }),
      keepPreviousData: true,
      initialCursor: 1
    });
  const queryInput = {
    locale,
    pageId: id,
    selectedFilterGuids: activeOptionsValues,
  };

  const { data, fetchNextPage, isFetchingNextPage } =
    trpc.epiApiRouter.artistLandingPage.useInfiniteQuery(queryInput, {
      ...reactQueryNoRefetch,
      getNextPageParam: (lastPage) => lastPage.lastPage + 1,
      initialData: () => ({ pageParams: [undefined], pages: [{ ...initialData }] }),
      keepPreviousData: true,
      initialCursor: 1
    });


activeOptionsValues
activeOptionsValues
is a
string[]
string[]
which is getting changed if I enable a filter. Somehow, only after the second change in the
queryInput
queryInput
the query refetches. You can see this in the screenshot I've provided.

If you have any idea what the problem could be I would be really thankful. Thank you all 🙂
image.png
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

SSR with initialData throws error
jlarmstJjlarmst / ❓-help
3y ago
state change not triggering refetch
neoneyNneoney / ❓-help
11mo ago
Validating inputs and outputs only via typescript
DangerZoneDDangerZone / ❓-help
2y ago