【发布时间】:2017-07-10 10:26:50
【问题描述】:
我正在构建一个 React Native 应用程序,并在我的注册表单中使用 Redux-form。我目前有一个表格并且成功,但我想仅在成功时导航到下一页。在我的代码中,我使用了 redux-form 的 onSubmitSuccess 函数,我需要使用道具导航到下一页,但是当我尝试在 onSubmitSuccess 中使用道具时,它告诉我“道具未定义”。在 redux-form v6.5.0 中,您可以将 props 传递给 onSubmitSuccess,但我不确定如何执行此操作。这是它的文档:https://github.com/erikras/redux-form/blob/master/docs/api/ReduxForm.md#onsubmitsuccess--function-optional
下面是我的代码的 sn-p:
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);
【问题讨论】:
标签: javascript forms react-native redux-form react-redux-form