this is the Table component
{this.props.tableData.map((item, index) => {
return (
<tr key={index}>
<td>{item.id}</td>
<td>{item.name}</td>
<td>{item.price}</td>
<td onClick={this.props.handleClick}></td>
</tr>)
})}
this is the parent component that invokes the Table component
<TableCom title={["id", "name", "price",""]}
tableData={this.props.reduxTableList}
handleClick={this.props.changeTable}>
</TableCom>
const mapDispatch = (dispatch) => {
return {
changeTable(){
dispatch(reduxTableState())
}
}
}
this is store"s reducer
export default (state = defaultState, action) => {
if (action.type === "changeTable") {
console.log(666)
return newState
}
I want to change the state value of table in store. I need to know which one to click on in store, so I need to know index
< td onClick= {this.props.handleClick (index)} > modify < / td >
this will not work