Question from the React (legacy) test

The component mixes display and retrieval of data.

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 1267 times
Edit
-2
Community Evaluations
developer avatar
François
13/10/2021
Il me semble que l'une des affirmations fausses et en réalité juste mais incomplète. C'est confusant.
developer avatar
Auteur anonyme
19/10/2021
Bonjour François, je peux t'envoyer le corrigé de cette question par email pour vérifier. Est-ce que cela t'intéresse ?
developer avatar
François
19/10/2021
Oui volontiers !