score:4

Accepted answer
import React, { cloneElement } from 'react';
import './style.css';

export default function App() {
  const name = 'Test';

  return (
    <Parent>
      <Wrapper myprops={name}>
        <Image />
        <House />
      </Wrapper>
    </Parent>
  );
}

function Parent({ children }) {
  return children;
}

function Wrapper({ children, ...props }) {
  return <>{children.map((child) => cloneElement(child, { ...props }))}</>;
}

function Image(props) {
  console.log(props);
  return <div>Image</div>;
}

function House(props) {
  console.log(props);
  return <div>House</div>;
}

score:0

function Wrapper({ children, ...props }) {
  return <>{children.map((child, i) => 
           <React.Fragment key={i}>
             cloneElement(child, { ...props }))
           </React.Fragment>}
         </>;
}

Related Query

More Query from same tag