I've read in many places that I shouldn't use this.state, but this.setState instead; the problem is that it won't work for my code. What am I doing wrong?
What I'm doing that works
submitForm = () => {
this.state.isAuthenticated = true
this.setState({
isAuthenticated: true,
userName: this.state.userName,
});
this.props.onLogIn(this.state.isAuthenticated, this.state.userName);
this.props.history.push("/predict");
};
What doesn't work for some reason
submitForm = () => {
this.setState({
isAuthenticated: true,
userName: this.state.userName,
});
this.props.onLogIn(this.state.isAuthenticated, this.state.userName);
this.props.history.push("/predict");
};