Skip to content
Advertisement

Adding items in the nested array of React state

I’m trying to add new items to an array of an object that resides in another object of a state. Pretty nested.

So I tried the following way…

JavaScript

Now I want to add another object inside the object of series array with useEffect(). And I tried:

JavaScript

The way I’m copying ...options works absolutely fine, But when I try to copy ...options.series it adds a new copied object inside the object of series array like the following:

JavaScript

The way I want the object to be is:

JavaScript

Can Anybody help me regarding this. I would appreciate any help.. Thanks

Advertisement

Answer

here is sample of what you are trying to achieve .

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement