Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| modul:ffit:react:learningunits:lu01:defining-a-component [2024/12/05 06:56] – angelegt kdemirci | modul:ffit:react:learningunits:lu01:defining-a-component [2024/12/05 07:08] (aktuell) – kdemirci | ||
|---|---|---|---|
| Zeile 5: | Zeile 5: | ||
| With <color # | With <color # | ||
| + | <code javascript> | ||
| + | function Product() { | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Return markup ===== | ||
| + | |||
| + | Each component must return a value. We create a <color # | ||
| + | |||
| + | <code javascript> | ||
| + | function Product() { | ||
| + | return ( | ||
| + | <div> | ||
| + | <img src=" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | ); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Export the component ===== | ||
| + | |||
| + | Now we have a component. But if we want to use it in other files, we need to export the function. To export a component, you need to add the keywords " | ||
| + | |||
| + | Product.js | ||
| + | <code javascript> | ||
| + | export default function Product() { | ||
| + | return ( | ||
| + | <div> | ||
| + | <img src=" | ||
| + | </ | ||
| + | ); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ProductsList.js | ||
| + | <code javascript> | ||
| + | import Product from ' | ||
| + | |||
| + | export default function ProductsList() { | ||
| + | return ( | ||
| + | <div> | ||
| + | < | ||
| + | <Product /> | ||
| + | <Product /> | ||
| + | <Product /> | ||
| + | <Product /> | ||
| + | </ | ||
| + | ); | ||
| + | } | ||
| + | </ | ||