![](/img/trans.png)
[英]How to send array of objects data from child component to parent component and store in the parent object using react hooks?
[英]How to store React component in object
我有一个所有应用程序的 object:
export const allApps: appInterface[] = [
{
id: uuidv4(),
name: "Minesweeper",
icon: minesweeperIcon,
disabled: false,
},
];
我想像这样向每个 object 添加组件属性:
export const allApps: appInterface[] = [
{
id: uuidv4(),
name: "Minesweeper",
icon: minesweeperIcon,
disabled: false,
component: Minesweeper, //It is imported as import Minesweeper from ../Components/Minesweeper";
},
];
然后我想在 App.js 中显示所有组件:
allApps.forEach((app)=>{
<div>{app.component}<div> // for eg: <div><Minesweeper/></div>
});
这可能吗?
试试下面的代码,它应该可以工作。
allApps.map((app)=>{
const { component: Component } = app;
return <Component />;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.