[英]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.