私はMobX 2.2.2を使用して、非同期アクション内で状態を変更しようとしています。私はMobXのuseStrictをtrueに設定しました。async関数と.thenとのMobX @actionデコレータの使用
@action someAsyncFunction(args) {
fetch(`http://localhost:8080/some_url`, {
method: 'POST',
body: {
args
}
})
.then(res => res.json())
.then(json => this.someStateProperty = json)
.catch(error => {
throw new Error(error)
});
}
私が取得:
Error: Error: [mobx] Invariant failed: It is not allowed to create or change state outside an `action` when MobX is in strict mode. Wrap the current method in `action` if this state change is intended
は、私は2番目の.then書に@actionデコレータを供給する必要がありますか?どんな助けもありがとう。
非同期/待つでこれを行うにはどのように? – TangMonk