[英]Handle multiple dispatch in react-native
我需要一些有关调用多个调度的帮助。 我有以下代码,但分派调用是异步的。 我不确定如何进行同步调度调用? 下面是我的代码。
componentDidMount () {
this.props.getItem1()
this.props.getItem2()
this.props.getItem3()
}
const mapStateToProps = state => ({
item1Fetching: state.item1.fetching,
item1Error: state.item1.error,
item2Fetching: state.item2.fetching,
item2Error: state.item2.error,
item3Fetching: state.item3.fetching,
item3Error: state.item3.error,
})
const mapDispatchToProps = dispatch => ({
getItem1: () => {
dispatch(Item1Actions.item1Request())
},
getItem2: () => {
dispatch(Item2Actions.item2Request())
},
getItem3: () => {
dispatch(Item3Actions.item3Request())
},
})
export default connect(mapStateToProps, mapDispatchToProps)(LoadingScreen)
作为一种变通方法,您可以创建一个要分派的动作,在执行该动作时,可以一一分派三种获取方法。
在您的mapDispatchToProps
方法中,您可以执行以下操作
const mapDispatchToProps = dispatch => bindActionCreators(itemsAction, dispatch)
在您的actions.js中,您可以执行以下操作...。
`export const itemsActions = () => {
return (dispatch, getState) => {
return item1Request().then((data) => {
dispatch(data);
return item2Request().then(data2 => {
dispatch(data2);
return item3Request().then(data3 => dispatch(data3))
})
})
}
}`
我希望这可以帮助你。 这样你就可以一一制作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.