-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Bug: Accessing this inside async/await returns undefined #6806
Comments
Hey @adeelshahid! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Your example is expected to fail, but the |
I've checked that this doesn't work with non-arrow functions, can be verified here |
@Andarist If it's not an arrow function then that's expected. If it's an arrow it gets turned into |
@loganfsmyth Non-arrow functions works though too, |
@Andarist The code sample in the issue is |
You are right, I've misread async's output and the |
+1, doesn't work with react? I've this config in .babelrc
|
@loganfsmyth @Andarist the process below works. If this solution looks good to you guys we can close this bug. try the following process,
Example constructor(props) {
super(props)
this.asyncFunc = this.asyncFunc.bind(this)
}
async function asyncFunc() {
try {
const result = await window.fetch(...)
} catch (e) {}
} |
@adeelshahid why can't I use arrow function? |
@eldyvoon babel transpilation does not correctly handle this reference when using bind and async together. Therefore I offered a workaround. |
This was a bug with react-hot-loader@3; it should be fixed with react-hot-loader@4. |
This issue is not reproduced in react-hot-loader 4. I checked it. |
@yakovenkoroman1993 if you don't mind, just use arrow function in jsx and do |
same as the issue #2765
Babel/Babylon Configuration (.babelrc, package.json, cli command)
Expected Behavior
This should point to Class instance. Even using onLogin = async () => {} returns undefined.
Current Behavior
It returns undefined. Async functions should not change this context.
The text was updated successfully, but these errors were encountered: