Question from the React (legacy) test

The component mixes display and retrieval of data.

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!