Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| de:modul:ffit:2-jahr:react:creating-a-component [2025/10/30 06:48] – angelegt kdemirci | de:modul:ffit:2-jahr:react:creating-a-component [2025/10/30 06:48] (aktuell) – gelöscht kdemirci | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== LU01a - Creating a component ====== | ||
| - | ===== Define the function ===== | ||
| - | |||
| - | 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 /> | ||
| - | </ | ||
| - | ); | ||
| - | } | ||
| - | </ | ||