I have an array of pointers, componentArray, but I'm struggling to figure out the syntax to both render them in ParentComponent
function Component1() {
return(
<h1>Hello from Component 1</h1>
);
}
function Component2() {
return(
<h1>Hello from Component 2</h1>
);
}
export const componentObject = [{
name: "Component1",
pointer: Component1
}, {
name: "Component2",
pointer: Component2
}];
function ParentComponent(props) {
return (
<div>
{Object.entries(componentObject).map((ChildComponent) => (
<span>{ChildComponent[1]() DOESNOTWORKPROP="Test"}</span>
))}
</div>
);
};
The above will work if you remove DOESNOTWKRPROP="TEST", but will not work when trying to add props to the children.
componentArray.map(Child => <Child prop={value} />).