0
我只是想知道如果我调用派遣和发送道具使用REDX并导航到另一个组件在同一个函数中,我如何确保我得到最新的道具之前呈现组件?得到最新状态之前调度react-navigation&redux
................
onSubmit() {
const { navigate } = this.props.navigation;
this.props.correctAnswer(30);
navigate('Another_Component',{score: this.props.totalScore});
}
return {
render(
<View>
<TouchableOpacity onPress={() => this.onSubmit()}>
<Text>ADD 30</Text>
</TouchableOpacity>
</View>
);
}
const mapStateToProps = (state) => {
return {
totalScore: state.CurrentActScore
}
}
const mapDispatchToProps = (dispatch) => {
return {
correctAnswer: (data) => {
dispatch({ type: 'ADD_SCORE', value: data})
}
}
}
...........
现在它仍然发送0,初始状态。
当我添加componentWillReceiveProps()时,它仍然使用旧值导航。 我认为在它完成过程和setState之前,它已经导航。