//parent
const Parent = ({ children }) => {
const [checked, setChecked] = useState(false);
const allChildren = React.Children.map(children, (child) => {
const clone = React.cloneElement(child, {
checked,
setChecked,
});
return clone;
});
return allChildren;
};
//child
const Child = ({ checked, setChecked }) => {
return (
<div onClick={() => setChecked(!checked)} style={{ color: "red" }}>
child content
</div>
);
};
//app
<Parent>
<Child />
</Parent>
//parent component which send the prop value
const parent=(val)=>{
return <Children value={val}/>;
}
//child component which recive the prop value
export const Children=(props)=>{
return props.value;
}
function Parent({children}) {
return (
<div>
{children}
</div>
);
}
export default function App() {
const Title = () => {
return <h2>Hello world</h2>;
};
return (
<div>
<Parent>
<Title />
</Parent>
</div>
);
}
[
{...,one : ComponentOne},
{...,two : ComponentTwo}
]
function Greeting(props){
return(<div>
//using p