Archived
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: ArchivedQuestion passed 1367 times
-3
Community EvaluationsNo one has reviewed this question yet, be the first!
6
Write a React function that fetches comments and passes them to a component.6
Optimize a React component by implementing shouldComponentUpdate2
Write a React component as a function5
How to submit a form in React2
Write the missing code to render the children of the UserProfile component.3
Fix the following React component: Scroller7
Improve this React component so that it displays "Green" by default.