score:1

Accepted answer

this is just an example to cover your case, so let say we have the table component which will just render all the code above

table

class table extends react.component {
  constructor() {
    super();

    this.onchange = this.onchange.bind(this);
    this.state = {
      tabledata: [
        ['one', 'two', 'three'],
        ['uno', 'dos', 'tres'],
        ['ichi', 'ni', 'san']
      ]
    };
  }

  renderrows() {
    const { tabledata } = this.state;

    return tabledata.map((cells, rowindex) => (
      <tr key={ rowindex }>
        {this.rendercells(cells, rowindex)}
      </tr>
    ));
  }

  rendercells(cells, rowindex) {
    return cells.map((cell, cellindex) => (
      <td key={ cellindex }>
        <input
          cellindex={cellindex}
          rowindex={rowindex}
          defaultvalue={cell}
          onchange={this.onchange}
        />
      </td>
    ));
  }

  onchange(event, cellindex, rowindex) {
    this.state.tabledata[rowindex][cellindex] = event.target.value;
    const tabledata = this.state.tabledata;

    console.log('values:', event.target.value, cellindex, rowindex);
    console.log('tabledata:', tabledata);

    this.setstate({ tabledata });
  }

  render() {
    return (
      <table>
        <tbody>
          {this.renderrows()}
        </tbody>
      </table>
    );
  }
}

input

function input({ onchange, cellindex, rowindex, defaultvalue }) {
  const oninputchange = event => {
    onchange(event, cellindex, rowindex);
  };

  return (
    <input
      type="text"
      value={defaultvalue}
      onchange={oninputchange}
    />
  );
}

there is nothing wrong with passing the index of the elements.
as you can see in the <input /> component you can pass the reference of rowindex and cellindex so you the component knows which element of the array is being updated and then notify it to the parent when the onchange event is triggered.

here is a working example of this, check it out: https://codepen.io/anon/pen/awjgkb?editors=0010


Related Query

More Query from same tag