一切工作正常,但我有這個警告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"/>
) // returnt
} // if-statement
}) // map-function
} // map-function __begin
</div> // comment.id
) // return
如果您不進入if,是否還有其他回報? – epascarello
只有'commentReply.replyTo === comment.id'時纔會返回。如果情況並非如此,你什麼都不會回來。只要在'if'塊後面加上'return null' –
Mikael Lennholm,我想說,你是天才 –