I wan to create an array/object of name and value pair of multiple input fields like [{street: value1, city: value2}].
import Input from 'react-toolbox/lib/input';
handleChange(name,value) {
var arr = [{[name]: value}];
}
<Input type='text' name='street' defaultValue={this.props.fieldValue}
onChange={this.handleChange.bind(this,"street")} />
<Input type='text' name='city' defaultValue={this.props.fieldValue}
onChange={this.handleChange.bind(this,"city")} />
I don't want to use react state. I have checked this: How to handle multiple controlled inputs with react es6? But there state has been used. Also followed this: How to add multiple form input results into array State in React.
I am guessing that, it can be resolved by lodash assign or Object.assign.
this.handleChange.bind(this). Then usehandleChange(event)and inside, getevent.target; that's the<input>. Grabevent.target.nameandevent.target.valuefor the name and current value.cityit returns{city: abc}and when I enter instreetit returns{street: xyz}. While I wants it like this:{city: abc, street: xyz}arr[e.target.name] = e.target.value;