Skip to content
Discussion options

You must be logged in to vote

search needs to be part of the queryKey:

  const [search, setSearch] = useRecoilState(searchAtom);
  const {
    status,
    data,
    fetchNextPage,
    hasNextPage,
  } = useInfiniteQuery(
    ['issuelist', search], // <--- here
    async ({ pageParam = 0 }) => {
      return await getIssues({ query: search, page: pageParam })
    },
    {
      getNextPageParam: lastPage => {
        return lastPage.nextId ? lastPage.nextId : false
      },
      refetchOnMount: false,
      refetchOnWindowFocus: false
    }
  )```

react-query will create a new cache entry and thus refetch if the key changes.

https://tkdodo.eu/blog/practical-react-query#treat-the-query-key-like-a-dependency-array

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryuhojin
Comment options

Answer selected by ryuhojin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants