I have a React functional component that returns a div containing child divs. It comprises an Item, and is used by another component to populate a list of Item rows. That list component gives each item an onClick event function, which I've placed on the outer div of each Item:
import React from 'react';
const Item = props => {
const { itemid, data, onClick } = props;
return (
<div itemid={itemid} type="button" tabIndex={0} onKeyPress={onClick} role="button" onClick={onClick}>
<div>
{itemid}
</div>
<div>
{data}
</div>
</div>
)
}
export default Item;
My thought is each entire Item row (both inner divs), when clicked, should trigger the onClick event attached to the outer div. But nope - the inner divs above do not apparently inherit the onClick event from the outer div.
The onClick event is only triggered by the inner divs if I attach it to them directly.
Is there some way to have the inner divs inherit the onClick attached to the outer div?