gpt4 book ai didi

reactjs - 需要帮助才能使 [create-react-app] 使用异步 - 等待(将异步转换为生成器)!

转载 作者:行者123 更新时间:2023-12-03 13:58:44 25 4
gpt4 key购买 nike

我是 [create-react-app] 的新手,我想知道如何将 ["transform-async-to-generator"] 添加到此构建过程中?在常规情况下,我会将其添加到 .babelrc 中,但看起来不适用于 [create-react-app]。

*通过“看起来不起作用”-我看到以下错误。

Syntax error: ../web/src/App.js: Unexpected token, expected ( (17:13)

15 | }
16 |
> 17 | test = async () => {
| ^
18 | let x = await this.resolveAfter2Seconds();
19 | try{}
20 | catch(exception){

有什么方法可以在不修改包本身的情况下扩展 [create-react-app] 吗?

谢谢!

最佳答案

问题不在于异步函数。您应该按以下方式重写代码:

// ...

test = async () => {
let x = await this.resolveAfter2Seconds();
// ...
}

// ...
async test(){
let x = await this.resolveAfter2Seconds();
// ...
}

关于reactjs - 需要帮助才能使 [create-react-app] 使用异步 - 等待(将异步转换为生成器)!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46640631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com