How I use React query: 1


How I use React query:

1. Create custom hooks that wrap related useQuery and useMutation calls.

2. Inline queryFn and mutationFn args. This enforces always using React query to query and mutate.

3. Colocate related queries and mutations in the same file, and invalidateQueries as part of the mutations.

4. Declare the keys at the top, so they can be reused in queries and mutations.

Example:

View original on X