i'm new to spread operations and i need some help or recommendations to add new replies to comment
my data structure is like this:
[
{
"id": 1,
"content": "first comment",
"replies": [
{
"id": 1,
"comment_id": 1,
"content": "first reply"
},
{
"id": 2,
"comment_id": 1,
"content": "seconds reply"
}
]
},
{
"id": 2,
"content": "second comment",
"replies": [
{
"id": 3,
"comment_id": 2,
"content": "third reply"
}
]
}
]
and new data:
{
"id": 4,
"comment_id": 2,
"content": "fourth reply"
}
the thing i wanted to do is:
const _reply = data =>
{
this.setState({
comments: // add new reply to comment by comment_id
})
}