React Comment List Insert comment data unshift

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.