I render the values that I have inside an object and an input next to each of them with that object index item as value. When I try to use the onChange prop, I cannot modify neither the rendered value nor the input value. How can I do this changing the state of the element in the array?
I want the Toto value to be modified as I change the input value

My object players looks like this:
[
{
"name": "Toto";
},
{
"name": "Lolz",
}
]
Here, I try to render my table:
modifyItem = (event, index) => {
this.state.players[index].name = event.target.value
//my problem is clearly here
}
render() {
const playersList = [...new Array(this.state.players.length)].map((it, index) => {
return (
<tr key={index}>
<td>{this.state.players[index].name}</td>
<input type="text" value={this.state.players[index].name} onChange={this.modifyItem}/>
</td>
</tr>
)
})
return () {
<div>
{playersList}
</div>
}
What I want to do is:
In each element of the table AND input ( for example the first one Toto), I want to modify this value in the input and consecutively in the table. I can't seem to find the correct answer.
[...]part. But that's a hugely convoluted way to just dothis.state.players.map(): pastebin.com/f1uMbtaKrenderfunction. You don't change things inrender. Please update your question with a minimal reproducible example demonstrating the problem, ideally a runnable one using Stack Snippets (the[<>]toolbar button). Stack Snippets support React, including JSX; here's how to do one.