Skip to content

useQuery hook not updated after parameter changes #2347

Answered by TkDodo
mickael-h asked this question in Q&A
Discussion options

You must be logged in to vote

react-query will not refetch on every re-render, that would be waaay too much. It will refetch if the key changes, so please put all your "dependencies" for the queryFn into the query key. Your queryFn uses user.uuid, so if you want react-query to refetch whenever the id changes, you have to make it part of the queryKey:

  const [user, setUser] = useRecoilState(userState);
  const {status, data} = useQuery(['points', user.uuid], () => getPoints(user.uuid), {
    refetchInterval: 5000,
  });

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mickael-h
Comment options

@shuvo-me
Comment options

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