I\'m trying to make a button that only redirects the user to a new page after validation is completed correctly.
Is there a way of doing something like this? How to I g
Like Purgatory said you can do it without using
, but otherwise you could make your component a stateful component and then do a conditional render like so
render() {
!this.state.redirect ?
:
}
And let the saveAndContinue()
change the component state.
saveAndContinue () {
var valid = validator.validate(this.props.form)
if (valid) {
axios.post('/path')
this.setState({redirect: true});
} else {
validator.showErrors()
}
}
When the state changes it would cause a re-render and this time the
would be rendered.
Note: I didn't actually run this code snippet, so it may contain (hopefully minor) errors.