I am getting the following warning when I try and change the value on an input field.
Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to
this.state
directly or define astate = {};
class property with the desired state in the Login component.
I cannot understand why this is happening, it is not happening on any of my other react pages.
The only difference is that this is the login page so has it's own routing to the page.
Can anyone help? I've stripped my component back to the bare bones to see if anyone can spot what I am doing wrong.
import React, { Component } from 'react';
class Login extends Component {
constructor(props) {
super(props);
this.state = {
username: ''
};
this.onChange = this.onChange.bind(this);
}
onChange(e) {
this.setState({ [e.target.name]: e.target.value });
}
render() {
const { username } = this.state;
return (
<input type="text" placeholder="Email" className="form-control" name="username" autoComplete="email" value={username} onChange={this.onChange} />
);
}
}
export default Login;