Cannot enable destructuring assignment to axios methods when apply this library
See original GitHub issueHi,
I cannot use tough cookie jar support v 0.5.0 with axios 0.19.0. on Noe.js v10.13.0
I have tried the example you have in the README.md but it is not working for me:
const axios = require('axios').default;
const axiosCookieJarSupport = require('axios-cookiejar-support').default;
const tough = require('tough-cookie');
const instance = axios.create({
// WARNING: This value will be ignored.
jar: new tough.CookieJar(),
});
// Set directly after wrapping instance.
axiosCookieJarSupport(instance);
instance.defaults.jar = new tough.CookieJar();
const { get, post } = instance;
The code fails here:
In the packaged lib its L73 in /lib/index.js:
EDIT:
fixed it by using instance instead of this in the anonymous function:
PR: https://github.com/3846masa/axios-cookiejar-support/pull/190
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Can't destructure data from axios post request response
this worked, and I was able to destructure the response. However my store seems to be adding undefined objects to the array even...
Read more >Understanding Axios GET requests - LogRocket Blog
Learn how to make GET requests in Axios with query parameters and API keys, plus concurrent and HEAD requests and error handling.
Read more >Cancel all axios requests in React's componentWillUnmount ...
Inside the constructor method, we assigned the cancel token source property to the source variable. source = axios.CancelToken.source();; Inside the fetchUser ...
Read more >Boot files - Quasar Framework
Notice we are using the ES6 destructuring assignment . ... Configure aspects of libraries - An example would be to create an instance...
Read more >Prevent Error with Default {} when Destructuring
When you use destructuring, make sure to set a default value of empty `{}` to prevent it from throwing an error...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
First, this two codes have same behavior, so my code hasn’t to modify for using normally. (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain for more details)
However, axios will bind this to own prototype when creating instance. https://github.com/axios/axios/blob/v0.19.0/lib/axios.js#L15-L26
Because of that, you can apply destructuring assignment to axios methods in current version.
I know it, but this behavior isn’t basic prototype behavior, so I decide I won’t support destructuring assignment.
FYI: If you want to use destructuring assignment, you can write wrapper code to bind this as below.
Thank you very much for this detailed answer!