[英]How to avoid re-rendering the whole List instead of adding the new item to the DOM list in react JS?
如果为列表中的每个项目赋予唯一(且确定性) key=uniqueValue
prop,则React将保留未更改密钥的列表项,从而避免重新呈现整个列表。
render() {
var comments = comments.map(function(comment){
return (
<Comment
key={comment.id} // This should be a unique, deterministic value
...
/>
);
});
return(
<div>
{comments}
</div>
);
}
阅读React 动态儿童文档部分中的更多内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.