commenList.map(item => {
// console.log('comment', item);
return (<div key={new Date().getTime()}>
<ExampleComment comment={item}
chooseId={this.state.chooseId}
loadchidren={loadchidren}>
{
item && item.tpCommentReplies.length > 0 ? item.tpCommentReplies.map(tgitem => {
return (<ChildrenComments key={new Date().getTime()}
comlength={item.tpCommentReplies.length}
chooseId={this.state.chooseId}
parentComment={item} childcomment={tgitem}></ChildrenComments>);
}) : ''
}
</ExampleComment>
</div>);
});
看到问题了嘛?其实知道是因为输入的时候引发重新渲染问题,但是不知道具体原因,其实就是map的key用的时间戳,可能是因为key 变化了,所以才引发了dom的重新渲染,而key如果用一样的就不会引发重新渲染,这就是react的机制吧,搞了一下午