New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
effects异步执行后,再更新state怎么做? #1612
Labels
Comments
个人觉得弹窗 state 放在 react component 的 state 会比较合适。 |
如果加在react component 的 state中,那么要在effects回调后如何触发state更新呢?我的问题就是这个。走componentWillReceiveProps 这个的生命周期去改变吗?还是其他的方式? |
我想到了个解决方案,不知道这样是否合适。 // route components.js
showDetail = (record) => {
const { dispatch } = this.props;
dispatch({
type: effects.getDetail,
payload: { id: record.id },
callback: () => {
this.setState({
detailVisible: true,
});
},
});
}; // models
effects: {
*getDetail({ payload, callback }, { call, put }) {
const response = yield call(getDetail, payload);
if (response.success) {
if (callback && typeof callback === 'function') {
callback();
}
yield put({
type: 'getDetailSuccess',
payload: response,
});
}
},
} |
不要用callback,每一个effects在dispatch后都会返回一个promise,在promise中处理弹窗就可以了 |
那怎么实现呢 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
预期的功能是在effects异步获取数据后,弹窗显示获得的数据。设置组件state标志属性用于组件是否显示。如果把标志位属性放在model的state中在页面跳转的时候,该标志位仍会保留状态返回页面时弹窗就又出现了,这是我不想要的。
The text was updated successfully, but these errors were encountered: