Requests vs. Mutations
Inspired by GraphQL, redux-query supports two types of queries:
- requests: Idempotent queries that read network data without side-effects. Default HTTP method: GET.
- mutations: Possibly destructive queries that mutate network data (i.e. the "C", "U", and "D" in "CRUD"). Default HTTP method: POST.
Key difference – avoiding unnecessary requests
If the same request (two queries are assumed to be the same if they have the same query key) has already been made and resulted in a successful server response, then the new request be ignored. It is possible to force a request to trigger a network request using the force
flag.
Mutations always trigger a network request.
How to make requests
Dispatch a requestAsync action with your Redux store.
If you'd like to make a request right from a React component, install redux-query-react and use either the useRequest and useRequests
hooks or the connectRequest HOC.
How to make mutations
Dispatch a mutateAsync action with your Redux store.
If you'd like to fire a mutation right from a React component, install redux-query-react and use the useMutation hook.