Question from the React (legacy) test

Optimize a React component by implementing shouldComponentUpdate

Hard

We want to optimize this component by implementing shouldComponentUpdate:

class Comments extends React.Component{
    constructor(props){
        super(props);
    }
    
    shouldComponentUpdate(nextProps, nextState){/* MISSING CODE*/}
    
    render(){
        return(
           <div>
               {this.props.comments.map((comment, i)=><p key={i}>{comment}</p>)}
           </div>
        );
    }
}

Comments.propTypes={
    comments: PropTypes.arrayOf(PropTypes.string).isRequired
};

Check the valid optimization(s):

Author: Victor SabatierStatus: PublishedQuestion passed 1394 times
Edit
4
Community EvaluationsNo one has reviewed this question yet, be the first!