问题描述:
- 在某个组件中.有可能频繁的取数据(但是数据未改变,因此不需要更新).
- 数据的频繁请求会触发render函数,造成性能消耗
- 模拟代码如下
export class CommentList extends Component {
constructor(props) {
super(props);
this.state = {
comments: []
}
}
// 模拟频繁的获取新数据
componentDidMount() {
setInterval(() => {
this.setState({
comments:[
{
body: '奇怪的栗子', author: 'odd marron'},
{
body: '好吃的栗子', author: 'nice marron'}
]
})
}, 1000)
}
render() {
return (
<div>
{
this.state.comments.map((c,