How do align with DRY coding when handling onChange for an simple contact form in React application?
I would like to pass an param with the state that should be updated
For example, simply having 4 inputs [name, phone, email, text] require 4 different eventhandlers updating different states of component, which is not great.
constructor(props) { super(props); this.state = { type: '', message: '', name: '', email: '', phone: '', content: '' }; } handleChange(e, state) { this.setState({state: e.target.value}); alert(state + " with val " + e.target.value) } This doesn't work and throwing an Cannot read property 'value' of undefined error
<input value={this.state.name} onChange={this.handleChange(name).bind(this)} id="firstName" name="firstName" autocomplete="off" type="text" required />