Why does Async Await work with React setState?

后端 未结 4 815
自闭症患者
自闭症患者 2020-12-12 20:54

I have been using async await with babel in my ReactJS project. I discovered a convenient use with React setState that I would just like to understand better. Consider this

4条回答
  •  借酒劲吻你
    2020-12-12 21:41

    The rv or return value of await is defined as:

    rv
    Returns the fulfilled value of the promise, or the value itself if it's not a Promise.
    

    So since handleChange is not an async or promise value, it's simply returning the natural value (in this case, there is no return, so undefined). Thus, there is no async event loop trigger here to "let it know handleChange is done", it simply just runs in the order you have given it.

提交回复
热议问题