Reactjs 我可以得到一个如何取消MobX流的示例吗?
Mobx官方文档声明,您可以对流返回的承诺调用cancel。没有关于如何做的例子 背景: 在componentDidMount中调用异步操作,我们需要在componentWillUnmount中取消此操作。还希望设置状态,说明用户界面可以在承诺解决后呈现Reactjs 我可以得到一个如何取消MobX流的示例吗?,reactjs,mobx,mobx-react,Reactjs,Mobx,Mobx React,Mobx官方文档声明,您可以对流返回的承诺调用cancel。没有关于如何做的例子 背景: 在componentDidMount中调用异步操作,我们需要在componentWillUnmount中取消此操作。还希望设置状态,说明用户界面可以在承诺解决后呈现 componentDidMount() { this._fetchRawEguide = this.props.combinedEguide.fetchRawEguide(null, true) .
componentDidMount() {
this._fetchRawEguide = this.props.combinedEguide.fetchRawEguide(null, true)
.then(() => {
this._fetchRawEguide = null;
this.setState({
loaded: true
});
})
}
componentWillUnmount() {
if (this._fetchRawEguide) {
this._fetchRawEguide.cancel();
}
}
Mobx操作看起来像这样
@action
fetchRawEguide = flow(function*(date, redirectOnError = false) {
try {
const res = yield request(...);
遇到一个问题,当它试图调用它时,它说.cancel()不存在
我曾尝试将when()与常规wait/async一起使用,但似乎不起作用。如果有人有一个wait/async的例子,那就太好了。这似乎是可行的
this._fetchRawEguide = this.props.combinedEguide.fetchRawEguide(null, true);
this._fetchRawEguide.then(() => {
this._fetchRawEguide = null;
this.setState({
loaded: true
});
});
我认为应用flow返回的承诺可能是铸造它并删除.cancel功能我的想法与我读到的完全相同,因此感谢您发布此问题,然后回答它!但是flow应该与使用
wait
而不是then()
和catch()
的async
函数一起使用,对吗?