I have a piece of state which holds an array of comments.
Each comment has an array of replies.
How can I add a reply value to the replies array of a specific comment within the comments array?
Here is my current attempt:
if (data) {
const isLargeNumber = (comment) => comment.id === reply.commentId;
const idx = comments.findIndex(isLargeNumber);
setPost({
...post,
comments: {
...comments[idx],
replies: [data.replyToComment, ...post.comments[idx].replies]
}
})
resetValues();
}
idx
holds the correct value I need but I do not think my implementation is correct here.