Using the MobX @action decorator with async functions and .then

后端 未结 3 696
一整个雨季
一整个雨季 2021-02-19 05:02

I\'m using MobX 2.2.2 to try to mutate state inside an async action. I have MobX\'s useStrict set to true.

@action someAsyncFunction(args) {
  fetch(`http://loca         


        
3条回答
  •  情歌与酒
    2021-02-19 05:18

    To complement the above answer; indeed, action only works on the function you pass to it. The functions in the then are run on a separate stack and should therefor be recognizable as separate actions.

    Note that you can also give the actions a name as well so that you easily recognize them in the devtools if you use those:

    then(action("update objects after fetch", json => this.someStateProperty = json))

提交回复
热议问题