score:4

Accepted answer

context api is used to share data between components in different nesting levels, you can read this from react doc:

context is primarily used when some data needs to be accessible by many components at different nesting levels. apply it sparingly because it makes component reuse more difficult.

for your case, your components image and house are at the same level. instead, you can use the composition and pass the props to your inner children like this:

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>;
}

this is a simple demo: https://stackblitz.com/edit/react-szxqwg

score:0

the answer of @soufiane boutahlil is legit, but you are missing a key prop. otherwise, react will go mad at you.

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