What do Args, api, extraOptions mean in RTK query?

Viewed 102

I'm trying my hands at RTK query(the pic is a ss of tutorial I was watching on the same topic), but I fail to understand what Args, api, extraoptions and tags do. I've read the documents but it ended up confusing me even more. Any easy explanation please? Also, is RTK query worth it or should I just stick to axios for data fetching and then use toolkit as a global data manager? I've tried asyncthunk but RTK query feels lightweight as statuses like(isloading, error and etc) are included and needs no manual coding.

enter image description here

1 Answers

These are the arguments your baseQuery will be called with whenever a query is executed.

  • args is the object that you return from the query function of your endpoint.
  • api is an object that contains a lot of information about the query that is currently going on
  • extraOptions is an extra property you can set on your endpoint and that will be passed through to the baseQuery.

As you are writing a wrapper around the baseQuery here, you don't have to interact too much with them - your own baseQuery is called with them and you just pass them on to the original baseQuery.

If you want to know what is really on all those, just console.log them or try autocomplete. You will probably end up using api.dispatch, but not too much else in most cases.

Related