I am building a very basic React application but having some issues with form inputs: My state:
class App extends Component {
constructor(){
super();
this.state = {
books: [],
book:{
author:"",
title: ""
}
}
this.handleInputChange = this.handleInputChange.bind(this)
}
My form:
<form onSubmit={this.addBook}>
<input
name="author"
type="text"
placeholder="author"
value={this.state.book.author}
onChange={this.handleInputChange}
/><br/>
<input
name="title"
type="text"
placeholder="title"
value={this.state.book.title}
onChange={this.handleInputChange}
/><br/>
<input type="submit" />
<button>Update</button>
<button>Delete</button>
</form>
My event handler:
handleInputChange(event) {
this.setState({
[event.target.name]: event.target.value
});
}
Still I am not able to digit in the input field. When I try to digit a value nothing happens and the input field is not updating properly. Any suggestions? Thanks