【发布时间】:2017-09-01 05:58:05
【问题描述】:
class Someclass {
@observable waiting = false;
@observable error = null;
@action.bound
async authenticate({login, password}) {
try {
this.waiting = true;
const res = await myService.authenticate(login, password);
} catch (error) {
this.error = error; // Gives an error: Invariant Failed
} finally {
this.waiting = false; // Gives an error: Invariant Failed
// I've tried doing this too
// action(() => {
// this.waiting = false;
// })
}
}
}
在上面的示例中,从 catch 和 finally 块中更改值会在严格模式下给出错误或警告 Invariant Failed。正确的做法是什么?
【问题讨论】:
标签: mobx mobx-react