Skip to content

Is there any way to declare augmented type for queryClient.setQueryData? #9159

Answered by yaindrop
yaindrop asked this question in Q&A
Discussion options

You must be logged in to vote

Just came across this thread, so it seems that currently the best we can do is

const meOptions = queryOptions({
  queryKey: ['auth', 'me'],
  queryFn: me,
})

export function useMe() {
  return useQuery(meOptions)
}

export function useLogin() {
  const queryClient = useQueryClient()

  return useMutation({
    mutationFn: ({ email, password }: { email: string; password: string }) => login(email, password),
    onSuccess: async data => {
      queryClient.setQueryData(meOptions.queryKey, data)
    },
  })
}

right? It looks good to me, but requires a bit of research to know...

Replies: 1 comment 1 reply

Comment options

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

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