DEV Community

loading...

Discussion on: Fast & easy... React states management in one function

Collapse
connect2amc profile image
Amit Chauhan
valueChange = (e) => {
    this.setState({
    [e.target.name]: e.target.value
    })
}

const {myFirstState, mySecondState} =this.state;

<input 
placeholder="insertValue" 
name="myFirstState" 
value={myFirstState}
onChange= {this.valueChange}/>

<input 
placeholder="insertValue" 
name="mySecondState" 
value={mySecondState}
onChange= {this.valueChange}/>