this.state = {
old: null,
new: null
}
componentDidMount() {
// get data
this.setState({old: data, new: data})
}
updateData() {
// some code
this.setState({new: newData})
}
Above code updates both old and new inside updateData() what i want is to get data and store in 2 different variable (old & new), update new with user input and compare/send to server etc..
EDIT: Input change part
<label for="pname">
Min: {this.state.old.parameters[i][1]}
</label>
<input
name={"p-" + item[0]}
className="form-control"
value={this.state.new.parameters[i][1]}
onChange={e => this.handleChange(e, i, 1)}
/>
Handle Change:
handleChange(e, i, x) {
let temp = this.state.new;
temp.parameters[i][x] = e.target.value;
this.setState({ new: temp });
}
EDIT: Here is a simple example to describe my issue. When you change first input all other inputs are also changing where they shouldn't