Δημιουργία Παιδικών Components στο React
Στα attributes των tags ενός component μπορούμε να μεταφέρουμε όχι μόνο strings, αλλά και να κάνουμε εισαγωγή μεταβλητών και σταθερών:
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>;
}
Δοκιμάστε όσα μάθατε σε κάποιο από τα components σας.