Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-query - What's the difference between useQuery and useMutation hook?

Tags:

react-query

Trying to find an answer regarding react-query.

What's the difference between useQuery and useMutation?

From what I understand, useQuery's are dependent calls.

useMutation is for posts that require updating the current state (cache invalidation, etc.)

Is that the correct assumption?

like image 955
chrisjlee Avatar asked Sep 03 '25 05:09

chrisjlee


1 Answers

From Tanner Linsley:

The difference is the flow of data. useQuery is used to query async data, useMutation is used to mutate it. Or in the traditional CRUD speak:

  • Read: useQuery
  • Create/Update/Delete: useMutation

https://twitter.com/tannerlinsley/status/1324384797939003393

like image 73
chrisjlee Avatar answered Sep 05 '25 01:09

chrisjlee