我是一个 React 菜鸟,正在制作一个 ToDo 列表样式的Recipe List 应用程序。我有一个功能组件 Item.js,我使用 JSX 和 map 函数遍历每个配方项并显示它们。我希望每个菜谱项都出现在一个新行上,但是当我使用 .map 遍历它们时,React 会将整个菜谱项列表放入一个 p 标记中,而不是每个项的一个 p 标记中。
如何遍历配方项并将它们显示在不同的行上?即使我尝试将它们显示为无序列表,React 也希望将每个项目放入一个 li 标签中。
这是我的代码:
import React from 'react';
import Button from 'react-bootstrap/lib/Button';
const Item = (props) => (
<div>
<div className="Recipe-Item-Container" key={props.text}>
{props.items.map((item, index) =>
<div className="Recipe-Item" key={index}>
<h3>{item}</h3>
<p>{props.ingredients[index]}</p>
<div className="buttons-container">
<Button className="edit-button" onClick={() => props.edit(item, index)}>Edit</Button>
<Button className="delete-button" onClick={() => props.delete(item, index)}>Delete</Button>
</div>
</div>
)}
</div>
</div>
)
export default Item;
也对{props.items.map((item, index) =>
,如果我以后添加大括号线=>我得到一个错误。我安装了 React/JSX linter,但它没有捕捉到任何东西。有什么问题?
我知道这可能是一个菜鸟错误,但 JSX 在这里让我循环。