I'm writing a React app and I'm struggling with the following problem. I have a table, let's say:
<Table>
<Row onClick={() => onRowClick(0)} >
<Cell innerComponent={row.cell[0].Component}/>
<Cell innerComponent={row.cell[1].Component}/>
<Cell innerComponent={row.cell[2].Component}/>
<Cell innerComponent={row.cell[3].Component}/>
</Row>
<Row onClick={() => onRowClick(1)} >
<Cell innerComponent={row.cell[0].Component}/>
<Cell innerComponent={row.cell[1].Component}/>
<Cell innerComponent={row.cell[2].Component}/>
<Cell innerComponent={row.cell[3].Component}/>
</Row>
</Table>
so it's just a table component with some element inside. I added the onRowClick
prop to the table but the issue is raised when the row.cell[_].Component
, that is rendered in the Cell, has a button inside. Indeed, in that case the onClick
of the button and the onRowClick is invoked that is partially wrong.
I know, I can use e.stopPropagation()
on the inner button onClick but this is easily forgettable and not so maintainable in a big team.
Do you have any suggestion how can I invoke the onRowClick only if this is the first onClick handler invoked instead of stop propagation from the inner handler?