javascript - 数组 map() 检索旧项目
问题描述
据我所知,The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
我有一个对象数组。我想渲染每个项目并且它工作正常!这是我正在使用的代码->
<div className="itemsSection__items">
{items &&
items.map((item) => {
return (
<Item
key={Math.random()}
imageUrl={item.image}
userName={item.userName}
/>
);
})}
</div>
但是在项目被渲染后,我试图安慰items
. 但它只给了我一个空数组([]
)。那么,即使在map
函数之后,我怎样才能检索项目?
编辑:
socket.on("connect", () => {
console.log("connected");
});
socket.on("newItem", (item) => {
const newItem = JSON.parse(item);
console.log(items)
});
在这里,当我尝试安慰这些项目时,它是一个空数组!
谢谢 !
解决方案
推荐阅读
- android - 如何使用 EditText 过滤 RecyclerView
- reactjs - 使用 React 和 Razzle 在一个或两个组件中应用 SSR(服务器端渲染)
- android - Android:如何在后台获取位置更新
- apache-spark - Spark 2.4 应用程序抛出 parquet 错误
- oracle - 检查 PL/SQL 中的列是否全部为 NULL
- php - 反转字符串中最后一个单词的字母顺序
- arrays - `A 型有什么区别
= T[]`和`类型B = [T]` - python - docker scrapy spyder 不会自动重启
- angular7 - 如何在Angular 7中只调用一次模板方法?
- mongodb - MongoDB中没有日期对象的比较查询