сначала вам нужно отрендерить все входные данные на основе вашего listQuestion внутри вашего рендеринга. Я предполагаю, что в массиве listQuestion для каждого вопроса он будет иметь уникальный идентификатор для каждого вопроса, на основе которого мы будем определять, какое значение изменяется.
{
listQuestion.map((item, index) => {
return (
<Input value = {item.value} onChange = {(e) => {this.handleOnChange(e,
item.id)} }></Input>
);
});
}
// item.id <= it is the unique identifier for each question object.
теперь вам нужно создать функцию, которая будет обрабатывать onChange
handleOnChange(e, id) {
const {listQuestion} = this.state;
listQuestion.forEach((item, index) => {
(item.id == id) {
item.value = e.target.value;
}
})
this.setState({listQuestion})
}
также внутри вашего конструктора
constructor(props) {
super(props);
this.state = {
listQuestion: []
}
this.handleOnChange = this.handleOnChange.bind(this);
}
скажем, у вас нет уникального идентификатора, тогда вы можете положиться на индекс, чтобы вы могли изменить это ...
<Input value = {item.value} onChange = {(e) => {this.handleOnChange(e,
index)} }></Input>
// it will send the index along with event, hence we can change value in listQuestion on the basis of index.
и просто измените это в функции onChange
handleOnChange(e, questionIndex) {
const {listQuestion} = this.state;
listQuestion.forEach((item, index) => {
(questionIndex == id) {
item.value = e.target.value;
}
})
this.setState({listQuestion})
}
// hence it will find the index in listQuestion array and change value of that particular index.