嗨,我在商店使用MobX,我需要有一个异步反应时计算出的值已经改变:MobX异步反应
class Store {
@observable user;
@observable something;
@computed get firstParam() {
return this.user && this.user.params[0];
}
async loadSomething() {
reaction(
() => this.firstParam,
async (param) => {
const { data: something } = await axios.get(`url/${param}`);
runInAction('update state after fetching something',() => {
this.something = something;
});
}
);
}
}
我想知道什么是这里是区别使用when
代替reaction
除了运行条件?
when(
() => !!this.firstParam,
async() => {
// fetch using this.firstParam
}
)