React में चाइल्ड कंपोनेंट्स बनाना
कंपोनेंट टैग्स के एट्रिब्यूट्स में आप सिर्फ स्ट्रिंग्स ही नहीं, बल्कि वेरिएबल्स और कॉन्स्टेंट्स भी पास कर सकते हैं:
function App() {
const name = 'product';
const cost = '100';
return <div>
<Product name={name} cost={cost} />
</div>;
}
चलिए एक साथ कई प्रोडक्ट्स बनाते हैं:
function App() {
const name1 = 'product1';
const cost1 = '100';
const name2 = 'product2';
const cost2 = '100';
const name3 = 'product3';
const cost3 = '100';
return <div>
<Product name={name1} cost={cost1} />
<Product name={name2} cost={cost2} />
<Product name={name3} cost={cost3} />
</div>;
}
आपके किसी एक कंपोनेंट पर सीखी हुई चीज को आजमाएं।