I have a table(array of objects) in React. I have a input box/ button for each row. Currently, I m using index in react local state (for input box/button). But 'index' results in messed up table, when filtered. Read link https://www.menubar.io/react-keys-index/ and trying to use 'keys'. Can someone help for accessing the array of input boxes and buttons using keys? My code is below:
companies.map((company,index)=>{
return (
<tr key={company.id}>
<td onClick={this.props.onClick.bind(this, company)}></td>
<td>{company.vacancy}</td>
<td key={company.id}>
<p><input type="text" value={this.state.company.messages[index] || ''} name={this.state.company.messages[index]} onChange={this.handleMessageChange.bind(this,company,index)}/></p>
<p><button type="button" onClick={() => this.sendSMS(company,index)}>SMS</button></p>
</td>
</tr>
);
})
I have companyId as unique value.