【发布时间】:2021-11-12 08:50:49
【问题描述】:
我想显示来自 react 的数组列表,但是当我认为我做的一切正确时它没有显示?请问我在哪里错了
下面是代码
import { useState } from 'react';
function App() {
const [items , setItems] = useState([{
id:1,
text:'simple 1'
},
{
id:1,
text:'simple 2'
},
{
id:1,
text:'simple 3'
},
])
return (
<div className="App">
{items.map((item) => (
<h1>{items.text}</h1>
))}
<h1>Hello from React js</h1>
</div>
);
}
export default App;
【问题讨论】:
-
<h1>{items.text}</h1>应该是<h1>{item.text}</h1>。并添加一个独特的keyprop -
哦,谢谢你,我完全忘记了
标签: arrays reactjs arraylist react-hooks