Hard
class Comments extends React.Component{
constructor(props){
super(props);
this.state={
comments:[],
isFetching: true
}
}
shouldComponentUpdate(nextProps, nextState){
return nextState.comments.length!== this.state.comments.length;
}
componentDidMount(){
fetchComments().then((comments)=>{
this.setState({comments, isFetching: false});
})
}
render(){
return(
<div>
{this.state.isFetching
?<p>Loading...</p>
: this.state.comments.map((comment, i)=><p key={i}>{comment}</p>)
}
</div>
);
}
}
Check the statement(s) that are true:
Author: Victor SabatierStatus: PublishedQuestion passed 1360 times
Edit
-3
Community Evaluations
Similar QuestionsMore questions about React