我正在构建一个反应本机应用程序,并且正在使用redux-form用于我的注册表格。我目前有一个表格和成功,我只想成功地导航到下一页。在我的代码中,我正在使用Redux-Form的OnSubMitSuccess函数,并且需要使用道具来导航到下一页,但是当我尝试在OnSubmitsuccess中使用Props时,它告诉我"道具未定义"。在redux-form v6.5.0中,您可以将道具传递给OnSubmitsuccess,但我不确定确切的方法。这是它的文档:https://github.com/erikras/redux-form/blob/master/master/docs/api/reduxform.md#onsubmitsuccess-function-tionction-function-punction-tional
下面是我的代码的片段:
render() {
const {handleSubmit, touched, error} = this.props
const onSubmit = (values, dispatch) => {
this.props.addFirstName(values.firstName)
this.props.addLastName(values.lastName)
this.props.addEmailAddress(values.emailAddress)
this.props.addPassword(values.password)
}
return (
<Container>
<View theme={theme}>
<Image source={require('../../../images/BG-signUp.png')} style={styles.background} >
<Content padder scrollEnabled={false}>
<Text style={styles.signupHeader}>
CREATE ACCOUNT
</Text>
<View style={styles.signupContainer}>
<Field name = "firstName" component = {renderFirstName} />
<Field name = "lastName" component = {renderLastName} />
<Field name = "emailAddress" component = {renderEmailAddress} />
<Field name = "password" component = {renderPassword} />
<Field name = "confirmPassword" component = {renderConfirmPassword} />
<Button
rounded transparent block
onPress={handleSubmit(onSubmit)}
style={styles.signupBtn}
>
Continue
</Button>
<TouchableOpacity>
<Text style={styles.termsText}>Terms & Conditions</Text>
</TouchableOpacity>
</View>
</Content>
</Image>
</View>
</Container>
)
}
function bindAction(dispatch) {
return {
addFirstName: (firstName) => dispatch(addFirstName(firstName)),
addLastName: (lastName) => dispatch(addLastName(lastName)),
addEmailAddress: (emailAddress) => dispatch(addEmailAddress(emailAddress)),
addPassword: (password) => dispatch(addPassword(password)),
reset: key => dispatch(reset([{ key: 'orgPage' }], key, 0)),
};
}
const mapStateToProps = state => ({
navigation: state.cardNavigation,
credentials: state.credentials
});
/*export default connect(mapStateToProps, bindAction)(SignUp);*/
SignUp = reduxForm({
form: 'signup',
validate,
onSubmitSuccess: () => {
this.props.reset(this.props.navigation.key)
}
})(SignUp);
SignUp = connect(mapStateToProps, bindAction)(SignUp);
SignUp = reduxForm({
form: 'signup',
validate,
onSubmitSuccess: () => {
this.props.reset(this.props.navigation.key)
}
})(SignUp);
this
在此脂肪箭头功能中没有任何意义。道具作为第三个参数将onSubmitSuccess
作为第三个参数。
SignUp = reduxForm({
form: 'signup',
validate,
onSubmitSuccess: (result, dispatch, props) => {
props.reset(props.navigation.key) // <---------
}
})(SignUp);
希望会有所帮助。