Skip to main content

Fetching Data

Using useQuery to fetch data

  • Directly use
  • Custom hook (Recommended)
Because react-query will cache data, I don’t know when it will be used multiple times, so I like to manage all of them with custom hooks (Single Source of Truth?)

Using react-router’s loader to fetch data

https://reactrouter.com/en/main/route/loader
  • Basic usage

use react-router + react-query to fetch data

I haven’t used it yet, I’ll write it when I use it
https://github.com/remix-run/react-router/tree/main/examples/query

Submitting Data

Using useMutation to submit data

Using react-router’s action to submit data

I haven’t used it yet, I’ll write it when I use it
https://reactrouter.com/en/main/route/action