I am buildng a react native app and am using Redux-form for my registration form. I currently have a form and on success, I would like to navigate to the next page only on success though. In my code, I am using redux-form's onSubmitSuccess function and I need to use props to navigate to the next page, but when I try using props in onSubmitSuccess it tells me that "props is not defined". In redux-form v6.5.0, you can pass props to onSubmitSuccess but I'm unsure of exactly how to do this. This is the documentation for it: https://github.com/erikras/redux-form/blob/master/docs/api/ReduxForm.md#onsubmitsuccess--function-optional
Below is a snippet of my code:
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
has no meaning inside of this fat-arrow function. The props are given to onSubmitSuccess
as the third parameter.
SignUp = reduxForm({
form: 'signup',
validate,
onSubmitSuccess: (result, dispatch, props) => {
props.reset(props.navigation.key) // <---------
}
})(SignUp);
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With