0
How do I take the values of two inputs and place inside an array with the event onChange
?
For example:
input1 = 10;
input2 = 20;
notas = [10, 20];
Follows the code:
import React, { Component } from "react";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
text: "",
notas: [],
};
}
input = (e) => {
this.setState({
[e.target.name]: e.target.value,
}, () => {
const array = [this.state.text]
this.setState({
notas: array
}, () => {
console.log(this.state.notas);
});
});
};
render() {
return (
<div>
<label>Nota 1</label>
<input type="text" name="text" onChange={this.input} /> <br /> <br/>
<label>Nota 2</label>
<input type="text" name="text" onChange={this.input} /> <br /> <br/>
</div>
);
}
}
Could someone help me ?
– daniel