无法迭代并传递“注释”作为嵌套在组件的“帖子”中

问题描述 投票:0回答:1

我的“评论”嵌套在来自Rails的名为“目击”的帖子中。我将'目击'阵列作为支柱传递给SightingContainer,然后传递给SightingCard。一切正常。然后我需要在同一张卡片中添加“评论”(评论是可评论的)。现在我将它作为一个单独的分支从App中处理,并将一系列'目击'(有嵌套的评论)发送到CommentsContainer然后发送到CommentsCard。在CommentContainer中,我正在进行2次迭代以深入查看“评论”。

我是一个React新手,所以我可能没有正确实现这一点。

我的ComponentContainer接受阵列props.sightings

import React from 'react';
import { Comment } from 'semantic-ui-react'
import CommentCard from '../components/CommentCard'


const CommentsContainer = props => {
  return (
    <div>
      {props.sightings && props.sightings.map(sighting => {
      return  sighting.comments.map((comment, idx) => {
        return <CommentCard key={idx} comment={comment} editComment={props.editComment}
          likeComment={props.likeComment} addComment={props.addComment}  currentUser={props.currentUser} deleteComment={props.deleteComment}/>
      })
    })
    }
    </div>
  )
};

export default CommentsContainer

我得到的错误是:


×
←→1 of 3 errors on the page
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

如果有人能告诉我更好的实施方法,请指教!

reactjs components iteration polymorphic-associations
1个回答
0
投票

因此,似乎整体React不能很好地嵌套数据。更好的是在后端处理它并将其作为非嵌套数据发送,即使它具有belongs_to或多态关系。

© www.soinside.com 2019 - 2024. All rights reserved.