Unshift new data on top
Insert Reply/Comment
else if (action.type = = = Insert_comment) {
let content = Action.text;
Let sendername = Action.replyname;
Let index = Action.index;
Let isreplycomment = action.isreplycomment;
Const OLDCOMMENTLIST = state.commentlist;
Console.log (444,oldcommentlist)
Main comment Data
if (!isreplycomment) {
Const NewComment = {
Sendername:sendername,
Content:content,
Createdtimestr: ' 2013 ',
ID: ' 777 ',
Likecount: ' 0 ',
Replycount: ' 0 ',
Repliedcommentlist: [],
};
Oldcommentlist.unshift (NewComment);
Console.log (444,oldcommentlist)
return {
... state,
Commentlist:oldcommentlist,
};
}
Sub-comment data
else {
Let NewList = oldcommentlist[index].repliedcommentlist;
Console.log (555,newlist);
Const Newchildcomment = {
Commentlist: ",
Sender: ' Receivername ',
Receivername:sendername,
Content:content,
CREATEDTIMESTR: ' 2016 ',
ID: ' 888 ',
Likecount: ' 0 ',
Replycount: ' 0 ',
};
Oldcommentlist[index].repliedcommentlist.unshift (newchildcomment);
Newlist.unshift (newchildcomment);
Console.log (555,newlist, 666, sendername,oldcommentlist);
return {
... state,
Commentlist:oldcommentlist,
}
}
}
React Comment List Insert comment data unshift