how to redirect a form to another page when we submitted a form in react js
onSubmitHandler = (e) => {
e.preventDefault();
this.setState({
showName: true
});
if(this.state.showName){
// submitting the form conditionally with javascript
document.getElementById("nameForm").submit();
}
}
render() {
return (
<div>
<form
onSubmit={this.onSubmitHandler}
id="nameForm"
action="https://google.com"
method="GET"
>
<label>Enter the Name</label>
<input type="text"
name="firstName" onChange={this.inputHandler} value=
{this.state.firstName} />
<button type="submit" onClick={this.onSubmitHandler}>Submit</button>
{this.state.showName && <p>"FirstName: " {this.state.firstName}</p>}
</form>
</div>
);
}