I'm new to React and I'm trying to make a Data Grid, it's working by now but I feel like I'm doing it wrong, here are the details:
Each row has multiple input (text, select, button), and we have the ability to delete, insert rows.
Now I have a GridComponent
that holds all the data as an array of objects. On render it will pass the object to RowComponent
with a handle to call when the input changes:
this.state.data.map((rowdata, index) =>
<RowComponent
key={rowdata.id}
rowdata={rowdata}
dataindex={index}
handleChange={this.handleChange}
/>
)
The problem is when RowComponent
calls handleChange
, the GridComponent
uses the rowindex to update the object. But it's slow and has a little delay while typing.
To solve that problem I then declare a state in RowComponent
to control the data while typing and only call handleChange
on the onBlur
event and it's working very well. But now I have 2 states in the Grid and Row, is it the correct way to do it?