my problem is that I keep getting an error "setState is not a function"
class UserLogin extends Component {
state = {
fullName: '',
password: '',
loader: false,
success: false,
fail: false
}
// update state with input value
handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
}
handleSubmit = (e) => {
e.preventDefault();
const fullName = this.state.fullName;
const password = this.state.password;
this.setState = ({ loader: true })
axios.post(`https://jsonplaceholder.typicode.com/users`, { fullName, password })
.then(res => {
console.log(res.data);
this.setState({ loader: false, success: true })
})
.catch(error => {
console.log(error)
this.setState({ loader: false, fail: true })
})
}
render() {
return (
<div>
<div>
<h1>Sign in</h1>
<input
name="fullName"
onChange={this.handleChange}
value={this.state.fullName}
/>
<input
name="password"
onChange={this.handleChange}
value={this.state.password}
/>
<button onClick={this.handleSubmit}>Login</button>
</div>
</div>
);
}
}
export default UserLogin;
my attempts to solve this was trying to bind things according to similar answers here, or adding a constructor but still only the input values are being updated and the fail, success, and loader in the state are still remaining false.