admin管理员组文章数量:1315369
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: .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" ponent = {renderFirstName} />
<Field name = "lastName" ponent = {renderLastName} />
<Field name = "emailAddress" ponent = {renderEmailAddress} />
<Field name = "password" ponent = {renderPassword} />
<Field name = "confirmPassword" ponent = {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);
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./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" ponent = {renderFirstName} />
<Field name = "lastName" ponent = {renderLastName} />
<Field name = "emailAddress" ponent = {renderEmailAddress} />
<Field name = "password" ponent = {renderPassword} />
<Field name = "confirmPassword" ponent = {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);
Share
Improve this question
asked Feb 21, 2017 at 0:15
kjwade3kjwade3
531 silver badge4 bronze badges
1 Answer
Reset to default 9SignUp = 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.
本文标签: javascriptHow do I pass props to the onSubmitSuccess callback in Redux FormStack Overflow
版权声明:本文标题:javascript - How do I pass props to the onSubmitSuccess callback in Redux Form? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741963832a2407430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论