0

I have the following onClick event:

const handleClickOpen = (id) => {
        const newPieChartData=pieChartData.map((item)=>{
            if (item.id===id){
                const newItem={
                    ...item , open:true
                }
                console.log(newItem)
                return newItem
            } return item
        })
        
        setPieChartData(newPieChartData)
        console.log(pieChartData)
        addPieChartGroup(id)
    };

And this is how I declare the onClick event in a child component:

onClick={()=>handleClickOpen(id)}

Yet the state

[
        {
            id:uuidv4(),
            data:[],
            open:false,
        }
    ]

doesnt change at all , which is reflected in the console.log (This is logged for newItem {id: "4d95df0a-d463-4981-91ec-20ea323414e0", data: Array(0), open: true} and this is logged for the pieChartData:{id: "4d95df0a-d463-4981-91ec-20ea323414e0", data: Array(0), open: false}) . Why is that ? Thank you very much !

Peter Malik
  • 308
  • 1
  • 9

0 Answers0