rtk-incubator / rtk-query

Data fetching and caching addon for Redux Toolkit
https://redux-toolkit.js.org/rtk-query/overview
MIT License
626 stars 31 forks source link

Make prepareHeaders support async functions #123

Closed schadenn closed 3 years ago

schadenn commented 3 years ago

I'm trying to use the prepareHeaders function to add an accessToken to my API requests. Unfortunately the function I'd have to use to get the accessToken in our setup is asynchronous.

So my proposal would be: Make the prepareHeaders function support async functions. Since this is being called in an asynchronous function anyways there's not a lot to change and it'd save us a lot of overhead by not having to put the accessToken into state first and then get it from there.

Hopefully it'll also help some other users :)

codesandbox-ci[bot] commented 3 years ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1d0d9dd52e137afac2e2d5c4dc26a210ee01b567:

Sandbox Source
React Configuration
React Typescript Configuration
rtk-query-demo Configuration
svelte-app-rtk-simplequery-demo Configuration
msutkowski commented 3 years ago

@schadenn Thanks for the PR! Do you mind if I add a quick test on top of this or would you be interested in doing that?

schadenn commented 3 years ago

I'll add it.

msutkowski commented 3 years ago

I'll add it.

Thank you! 🥇

schadenn commented 3 years ago

Done :)