Search code examples
axiosblobredux-toolkitrtk-query

Using RTK Query what is the best practice to download a file


I am currently working on updating my react app with RTK Query.
Historically I am using Axios to communicate with my backend.

I can easily replace most of my endpoint using RTK Query and I am very happy with the results, however I understood that getting file or any blob with RTK Query is a bad idea as it will be cached in the browser and that is not what I want.

My question is what is the best practice there ? Is it ok to keep using axios for my download or is there a best practice here ?

Thanks.


Solution

  • You are correct that this is outside of the scope of RTK Query. You can just use what you always have been using, although I would generally recommend fetch over axios, as it is part of the browser and doesn't require an extra package to be added to your bundle.