Creating Child Components in React
You can pass not only strings to the component tag attributes, but also insert variables and constants:
function App() {
const name = 'product';
const cost = '100';
return <div>
<Product name={name} cost={cost} />
</div>;
}
Let's make several products at once:
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>;
}
Try out what you've learned on one of your components.