I am trying to send the id of the respective object through an on-click event , yet I always end up being sent the synthetic onClick event , how can I change this ? How my array of objects looks like :
JavaScript
x
7
1
[
2
{
3
id:uuidv4(),
4
data:[]
5
}
6
]
7
My onClick={(id)=>handleOpen(id)}
EDIT: It was recommended to change the renderig of the button in the following way :
JavaScript
1
2
1
<button onClick={(e)=>addPieChartGroup(e.target.id)}>Add</button>
2
Thank you very much !
Advertisement
Answer
you can also do like that so when ever your items got update the map function adjust all index automatically
JavaScript
1
4
1
const dataArray = [ { id:uuidv4(), data:[] } ]
2
3
handleClick = (dataObj) =>{ console.log(dataObj) }
4
In render
JavaScript
1
2
1
dataArray.map((obj, index) => <Button id={index} onClick={handleClick(obj)}> Click Me </Button> )
2