我正在使用MobX 2.2.2尝试在异步操作中改变状态.我将MobX的useStrict设置为true.
@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)
});
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
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
Run Code Online (Sandbox Code Playgroud)
我是否需要将@action装饰器提供给第二个.then语句?任何帮助,将不胜感激.