From c781b8c0bf73c08380343a345d8574d61f905dfd Mon Sep 17 00:00:00 2001 From: Philippe Torrel Date: Wed, 26 Aug 2026 09:39:22 +0200 Subject: [PATCH] --- .../tag52/01_react-app-performance/src/App.jsx | 8 ++++++-- .../src/components/examples/ExampleUseCallback.jsx | 3 ++- .../src/components/examples/ExampleUseMemo.jsx | 10 +++++----- .../src/components/examples/LazyComponent.jsx | 10 ++++++++-- 05_react/unterricht/tag52/react-app/package-lock.json | 4 ++-- 05_react/unterricht/tag52/react-app/package.json | 4 ++-- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/05_react/unterricht/tag52/01_react-app-performance/src/App.jsx b/05_react/unterricht/tag52/01_react-app-performance/src/App.jsx index bb4cec2..5829b83 100644 --- a/05_react/unterricht/tag52/01_react-app-performance/src/App.jsx +++ b/05_react/unterricht/tag52/01_react-app-performance/src/App.jsx @@ -28,12 +28,16 @@ function App(props) {

+

useCallback mit ref- Attribut

- {/*
- */}
+

useRef - Hook

+ +
+

useCallback auf EventHandler angewandt


+

memo - Funktion von React


diff --git a/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/ExampleUseCallback.jsx b/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/ExampleUseCallback.jsx index fc4e2bc..05138c6 100644 --- a/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/ExampleUseCallback.jsx +++ b/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/ExampleUseCallback.jsx @@ -8,6 +8,7 @@ const ExampleUseCallback = (props) => { { id: 1, title: 'Product 1', description: 'lorem ipsum', price: 10 }, { id: 2, title: 'Product 2', description: 'ipsum lorem', price: 20 }, { id: 3, title: 'Product 3', description: 'lorem dolor', price: 30 }, + { id: 4, title: 'Witcher 3', description: 'free update', price: 0 }, ], ); @@ -47,7 +48,7 @@ const ExampleUseCallback = (props) => {
    {products.map((product) => ( { handleClick(e, product.id); diff --git a/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/ExampleUseMemo.jsx b/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/ExampleUseMemo.jsx index 7e29447..9803b39 100644 --- a/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/ExampleUseMemo.jsx +++ b/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/ExampleUseMemo.jsx @@ -13,7 +13,7 @@ const ExampleUseMemo = (props) => { const productsAmount = useMemo(() => { console.log('Calculating the number of products'); return products.length; - }, [products]); + }, [products]); // Bei Veränderung des "states" (hier: products) wird der Funktionsausdruck neu ausgeführt und der Rückgabewert in die Variable geschrieben // EventHandler const handleChangeText = (e) => { @@ -21,10 +21,10 @@ const ExampleUseMemo = (props) => { }; // Functions - // const getNumberProducts = () => { - // console.log('Calculating the number of products'); - // return products.length; - // }; + const getNumberProducts = () => { + console.log('Calculating the number of products'); + return products.length; + }; return (
    diff --git a/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/LazyComponent.jsx b/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/LazyComponent.jsx index e82178e..8b4e0f2 100644 --- a/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/LazyComponent.jsx +++ b/05_react/unterricht/tag52/01_react-app-performance/src/components/examples/LazyComponent.jsx @@ -1,13 +1,19 @@ +import { useState } from 'react'; + const LazyComponent = (props) => { // const { } = props; + const [textLoaded, setTextLoaded] = useState(''); + // Simulate a slow content placement // TODO: replace with fetch component const wait = (delay) => new Promise((resolve) => setTimeout(resolve, delay)); - wait(3000); + wait(3000).then(() => { + setTextLoaded('Content fully loaded'); + }); return (
    -

    I was loaded late!

    +

    I was loaded late: {textLoaded}

    This text only appears after the code for this component has been loaded

    ); diff --git a/05_react/unterricht/tag52/react-app/package-lock.json b/05_react/unterricht/tag52/react-app/package-lock.json index b501afe..8b27f45 100644 --- a/05_react/unterricht/tag52/react-app/package-lock.json +++ b/05_react/unterricht/tag52/react-app/package-lock.json @@ -16,9 +16,9 @@ }, "devDependencies": { "@types/react": "^19.2.18", - "@types/react-dom": "^19.2.4", + "@types/react-dom": "^19.2.5", "@vitejs/plugin-react": "^6.1.0", - "oxlint": "^1.79.0", + "oxlint": "^1.80.0", "sass-embedded": "^1.103.1", "vite": "^8.2.2" } diff --git a/05_react/unterricht/tag52/react-app/package.json b/05_react/unterricht/tag52/react-app/package.json index bf441d0..882699a 100644 --- a/05_react/unterricht/tag52/react-app/package.json +++ b/05_react/unterricht/tag52/react-app/package.json @@ -18,9 +18,9 @@ }, "devDependencies": { "@types/react": "^19.2.18", - "@types/react-dom": "^19.2.4", + "@types/react-dom": "^19.2.5", "@vitejs/plugin-react": "^6.1.0", - "oxlint": "^1.79.0", + "oxlint": "^1.80.0", "sass-embedded": "^1.103.1", "vite": "^8.2.2" }