Let's say we have a simple function component:
const Dummy = () => {
return <div>Dummy</div>;
};
export default Dummy;
And let's say that we pass this component as a prop to another component:
<App
componentA={<Dummy />}
componentB={Dummy}
/>
And here's the App.js code:
import React from "react";
export default function App({ componentA, componentB }) {
const ComponentA = componentA;
const ClonedA = React.cloneElement(componentA, { anotherProp: "yes" });
const CreatedA = React.createElement(componentA, { anotherProp: "yes" });
const ComponentB = componentB;
const ClonedB = React.cloneElement(componentB, { anotherProp: "yes" });
const CreatedB = React.createElement(componentB, { anotherProp: "yes" });
return (
<div>
{/* <ComponentA /> */}
{/* <ClonedA /> */}
{/* <CreatedA /> */}
<ComponentB />
{/* <ClonedB /> */}
{/* <CreatedB /> */}
</div>
);
}
How can I extend componentA and componentB and render them? All of the lines that are commented out break the code.
Here's the codesandbox for this code.