import { Redirect } from "react-router-dom"
......
state = { shouldRedirect: false, error: null }
onSubmit = () => {
const response = /* ..... true | false */
this.setState({
shouldRedirect: response,
error: response ? null : 'Something wrong!'
})
}
render() {
if (this.state.shouldRedirect) return <Redirect to="/" />
return (
{ this.state.error && <div className="error">{this.state.error}</div> }
.......
)
}