This is an example table data:
const tableData = [
['one', 'two', 'three'],
['uno', 'dos', 'tres'],
['ichi', 'ni', 'san']
]
The data will be rendered like this:
render() {
<Table>
<Table.Body>
{
tableData.map((row, rowIndex) => {
return (
<Table.Row key={ rowIndex }>
{
row.map((cell, cellIndex) => {
return (
<Table.Cell key={ cellIndex }>
<Input
defaultValue={ cell }
onChange={ this.tableChange }
/>
</Table.Cell>
)
})
}
</Table.Row>
)
})
}
</Table.Body>
</Table>
}
Now I need to get an updated dataset on onChange of an Input element.
tableChange(event) {
console.log(event.target.value)
}
This is how I get the updated current element value. But I need to get the complete updated array - like the input array.
I would think of using the key values, but maybe I need some data-attributes?
Inputcomponent? or is it a library?Inputcomponent you can add a prop likeindexthat the actual position of the value,<Input defaultValue={ cell } onChange={ this.tableChange } index={cellIndex} />and return it in your input click handler