-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple axios instances #98
Comments
can you explain what would be the use case you're trying to accomplish? |
For example, in one of the projects I'm working on now, we have to make ourApi.jsimport axios from 'axios';
export default axios.create({
baseURL: 'http://our-api.com'
}); externalService.jsimport axios from 'axios';
export default axios.create({
baseURL: 'http://external-service.com',
params: {
appid: 'mysecretkey'
}
}); Now, without BUT, with But ATM there is no way to reference/use a different |
Yeah the scenario is a reasonable one, I think I would prefer to go with a hook creator, exported as a named export from the package, something along the lines of:
What do you think? |
I'm working on a PR to add this, please check it out and let me know if you have thoughts. #100 |
Hey, @simoneb , thanks for the quick |
See README for details about how to use the feature: https://github.com/simoneb/axios-hooks/#multiple-hook-instances fix #98
@CloudPower97 see #100 and the updated README which includes an example. To answer your questions:
I published a prerelease 1.8.0-0 version on NPM so you can try it out. Would this work for you? |
@CloudPower97 do you have any thoughts on this? |
Hey, @simoneb, sorry for this late answer.
The code that is throwing this error is: useApi<Colture[]>(
{
url: '/diz-coltures',
...config
},
options
); where Anyway, thank you for your time, I do really appreciate! |
Can you please post the error in full? I can't see what the compiler is complaining about. |
@CloudPower97 thanks for checking. There was indeed a problem with the TS type definition. Fixed in 1.8.0-2. Can you update and try again? |
@simoneb Everything works fine now, thank you! |
@CloudPower97 thanks for helping to troubleshoot the issue! I'll release this feature soon. |
Hello @simoneb ,
is there a way to use multiple
axios
instances
?As far as I understand,
configure
accept a single instance.Is there something I'm missing or is this funcionality not present ATM?
Is it going to be possible?
Maybe something like:
(In either cases defaults to firstInstance if not specified)
and then use it like that:
This is my general idea.
Do you think that something along the lines of that is possible to achieve?
Thank you for your time!
The text was updated successfully, but these errors were encountered: