Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
modul:ffit:react:learningunits:lu01:using-variables [2024/12/05 07:18] – angelegt kdemirci | modul:ffit:react:learningunits:lu01:using-variables [2024/12/18 16:11] (aktuell) – kmaurizi | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====== LU01b - Using Variables ====== | ====== LU01b - Using Variables ====== | ||
- | We can use variables to fill out our component dynamically. In JSX we have to use the curly brackets {} to display value. | + | We can use variables to populate |
- | <code javascript> | + | Product.js |
- | export default function Product() { | + | <file javascript |
+ | export default function Product(props) { | ||
return ( | return ( | ||
<div> | <div> | ||
< | < | ||
- | src=" | + | src={props.image} |
alt=" | alt=" | ||
width={300} | width={300} | ||
height{300} | height{300} | ||
+ | /> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | ); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ProductsList.js | ||
+ | <code javascript> | ||
+ | import Product from ' | ||
+ | |||
+ | export default function ProductsList() { | ||
+ | return ( | ||
+ | <div> | ||
+ | < | ||
+ | < | ||
+ | title=" | ||
+ | image=" | ||
+ | description=" | ||
+ | price=" | ||
+ | /> | ||
+ | < | ||
+ | title=" | ||
+ | image=" | ||
+ | description=" | ||
+ | price=" | ||
+ | /> | ||
+ | < | ||
+ | title=" | ||
+ | image=" | ||
+ | description=" | ||
+ | price=" | ||
+ | /> | ||
+ | < | ||
+ | title=" | ||
+ | image=" | ||
+ | description=" | ||
+ | price=" | ||
/> | /> | ||
</ | </ | ||
Zeile 18: | Zeile 59: | ||
</ | </ | ||
+ | ===== Using children of component ===== | ||
+ | We can nest components and also use other elements in our component brackets. | ||
+ | |||
+ | Content.js | ||
+ | <code javascript> | ||
+ | export default function Content(props) { | ||
+ | return ( | ||
+ | <section className=" | ||
+ | {props.children} | ||
+ | </ | ||
+ | ) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | App.js | ||
+ | <code javascript> | ||
+ | import Content from " | ||
+ | import ProductsList from " | ||
+ | |||
+ | export default function App() { | ||
+ | return ( | ||
+ | <div className=" | ||
+ | < | ||
+ | This is my content. | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | ) | ||
+ | } | ||
+ | </ |