I have a React state object with two arrays inside of it.
this.state = {
data2: {
nodes: [{id: 'input'}],
links: []
},
};
I want to add new values to these arrays after some user action but I haven't figured out the right way. So far I have attempted something like this:
this.setState([...this.state.data2, {nodes: [...this.state.nodes,{ id: 'input2'}]}]);
Any ideas on how should I implement this?