Question from the React (legacy) test

Write a React function that fetches comments and passes them to a component.

Hard
function withComments(WrappedComponent){
    class CommentsFetcher extends React.Component{
        constructor(props){
            super(props);
            this.state={
                comments:[],
                isFetchingComments: true,
                commentsError: null,
            };
        }
        
        componentDidMount(){
            fetchComments()
               .then((comments)=>this.setState({comments, isFetchingComments: false}))
               .catch((error)=>this.setState({isFetchingComments: false, commentsError: error}));
        }
        
        render(){
            return<WrappedComponent{... this.props}{... this.state}/>;
        }
    }
    
    return CommentsFetcher;
}

Check the statement(s) that are true:

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