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 (
      <wrapper myprops={name}>
        <image />
        <house />

function parent({ children }) {
  return children;

function wrapper({ children, ...props }) {
  return <>{ => cloneelement(child, { ...props }))}</>;

function image(props) {
  return <div>image</div>;

function house(props) {
  return <div>house</div>;

this is a simple demo:


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 <>{, i) => 
           <react.fragment key={i}>
             cloneelement(child, { ...props }))

Related Query

More Query from same tag