reactjs - 将变量连接到数组映射方法
问题描述
我将一个变量传递给组件,如下所示,并将其映射到过滤数组
例子:
<TestSection name={Stackoverflow} />
在 Testsection 组件中
const TestSection = ({ name }) => {
const Data = useStaticQuery(
graphql`
query {
Json {
TEST {
Stackoverflow {
title
description
}
Overflowstack {
title
description
}
}
}
}
`
);
console.log(name) // this outputs Stackoverflow and this should be the input for map function
return (
{Data.Json.TEST.name.map((item, index) => (
<div key={`test-${index}`}>
<ul>
<li>{item.title}</li>
<li>{item.description}</li>
</ul>
</div>
))}
);
};
将名称传递给地图数组不起作用。目的是根据调用组件名称返回数组数据。如何将名称传递给地图数组?谢谢
解决方案
推荐阅读
- amazon-web-services - 基础架构代码是否应该与应用程序代码存储在同一个存储库中?
- javascript - 为什么“this.todos = [...this.todos, todo]”而不是推动?
- node.js - 有没有办法使用 Node.js 域模块获取父域?
- cmake - CMake 错误 buildir" 似乎不包含 CMakeLists.txt
- python - 重塑 3D 数组的正确方法
- python - 使用 python/reges 从 CSV 中查找 lat 和 long
- vba - 根据列表框选择删除表格行
- javascript - 调试 Java stream() NullPointerException 原因的最佳方法
- python - 在使用 tensorflow 库训练深度学习模型时出现错误:ResourceExhaustedError OOM on gpu(128 gb RAM) 请帮助我
- php - 尝试从 PHP 页面执行 node.js 命令