React Children Props (props.children)
Children Props (props.children)
React-da siz tarkibni componentning ochilish va yopish teglari orasidagi boshqa componentga yuborishingiz mumkin.
Bunga props.children xususiyati yordamida boshqa componentda kirish mumkin.
Misol
Parent componentidan tarkibni Son va Daughter componentlarining ochilish va yopish teglari orasiga yuboring:
function Son(props) {
return (
<div style={{background: 'lightgreen'}}>
<h2>Son</h2>
<div>{props.children}</div>
</div>
);
}
function Daughter(props) {
const {brand, model} = props;
return (
<div style={{background: 'lightblue'}}>
<h2>Daughter</h2>
<div>{props.children}</div>
</div>
);
}
function Parent() {
return (
<div>
<h1>My two Children</h1>
<Son>
<p>
This was written in the Parent component,
but displayed as a part of the Son component
</p>
</Son>
<Daughter>
<p>
This was written in the Parent component,
but displayed as a part of the Daughter component
</p>
</Daughter>
</div>
);
}
createRoot(document.getElementById('root')).render(
<Parent />
);
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
