seems like ? a “react” version of axios

with hooks to support data which updates

hol up

it needs a queryfn inside of which i need to manually write a http request

hmmm there are keys which you can invalidate, which are really nice, im starting to see the usecase

there are many hooks shipped with the package

to handle mutations, query, queries, fetching, is mutating, suspensequery?, hydration and stuff too

if it works well to sync state between the server & the frontend, im here for it


life without react-query:

  • have a fetch function where you call the actual api and serialize the json
  • set an useEffect hook to call the function on every page load and set data via useState
  • gets messy real quick
  • gets very hard to handle caching, retries, deduping

react query:

  • cleans up code
  • adds a bunch of features like retries, infinite queries
  • optimistic updates
  • very good debugging
  • automatic retries on errors
  • dependent queries

Usage:

  • setup query client
  • set provider with the client
  • inside component, call useQuery with loading, error and data states
  • setup mutations to change the state on the server
    • hook into it and invalidate the query and auto refresh using the key
  • setup links with other queries and conditions based on synced state

this is amazing lol