Skip to content

react-query + useSnapshot & "Beter to use proxy state" eslint warning #885

Answered by dai-shi
peterpme asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah, with react-query, I think your code is correct, because of queryKey.
However, eslint-plugin-valtio doesn't know its semantics.

For this specific case, my suggestion is to avoid inlining query key in query function.

export function useUserFriends() {
  const { userId } = useSnapshot(store);

  return useSuspenseQuery({
    queryKey: [userId, "friends"],
    queryFn: async ({ queryKey }) => {
      const [userId] = queryKey;
      const friends = await fetch(/* ... */);
      return processData(userId, friends);
    },
  });
}

Replies: 1 comment 1 reply

Comment options

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

Answer selected by peterpme
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