【发布时间】:2020-08-28 13:45:33
【问题描述】:
一个 React 组件可以用 2 个类渲染吗?就像我在图片中所做的那样。
我尝试了上述方法。它给了我另一个错误Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of "Groups".
我在 Groups 方法(Groups.jsx)中使用的按钮组件就是这样。
const Groups = (props) => (
<div className = 'panel'>
<h2>Groups</h2>
<button >Get Groups</button>
<div className = 'group-list'>
{props.groups.map((group) =>
<GroupsEntry name = {group.name}
members = {group.members}/>
)}
</div>
</div>
);
你们对此有什么想法吗?谢谢
【问题讨论】:
-
你能提供你用来渲染这个的完整代码吗?如果您使用
map创建子组件,您可能需要添加key属性。文档:reactjs.org/docs/lists-and-keys.html -
我只是在我的帖子中添加了我的按钮组件的代码。谢谢。
标签: reactjs components key unique react-props