Everything works fine, but I have this warning Expected to return a value at the end of arrow function array-callback-return. I tried using forEach instead of map, but then <CommentItem /> doesn't even show. How do I fix this?
Expected to return a value at the end of arrow function array-callback-return
forEach
map
<CommentItem />
return this.props.comments.map((comment) => { if (comment.hasComments === true) { return ( <div key={comment.id}> <CommentItem className="MainComment"/> {this.props.comments.map(commentReply => { if (commentReply.replyTo === comment.id) { return ( <CommentItem className="SubComment"/> ) // return } // if-statement }) // map-function } // map-function __begin </div> // comment.id ) // return
A map() creates an array, so a return is expected for all code paths (if/elses).
map()
return
If you don't want an array or to return data, use forEach instead.
1.4m articles
1.4m replys
5 comments
57.0k users