From c4d14d6f2387fd872ba262208f435ab3f8588456 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 14 Jul 2026 15:35:18 +0200 Subject: [PATCH] Readme angepasst, Leserlichkeit im Code leicht verbessert --- README.md | 12 ++++++++++-- react-unterricht-todolist/src/App.jsx | 2 ++ .../src/components/TodoForm.jsx | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0e70c28..2088ee2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ -# React App zum Laufen bringen -1. 'react-todolist' Ordner in Eingabeaufforderung oder PowerShell öffnen +# Inhalt des Repositories +In dem Repositories liegen die Dateien des aktuellen Bausteins WJSF. Neben den reinen html/css/js-Seiten sind aktuell drei React-Apps enthalten. + +Die React-Apps liegen in den Verzeichnissen 'Erster React Test', 'react-todolist' und 'react-unterricht-todolist'. + +react-todolist enthält eine für React angepasste Todo-App von Montag. react-unterricht-todolist ist eine vereinfachte Variante der heute (Dienstag) vorgestellten App (keine API-Aufrufe, keine Statistiken). + +React Apps lassen sich nach klonen des Repositories nicht einfach so öffnen. Es müssen erst Pakete etc. nachgeladen werden. Dafür kann die untenstehende Anleitung verwendet werden. +# React Apps zum Laufen bringen +1. Mit Eingabeaufforderung oder PowerShell Ordner mit React-App öffnen 2. `npm install` -> npm installiert Abhängigkeiten für React 3. `npm run dev` -> npm startet React-Development-Server; Ausgabe sollte ungefähr sein: ``` diff --git a/react-unterricht-todolist/src/App.jsx b/react-unterricht-todolist/src/App.jsx index a85eb75..b09220c 100644 --- a/react-unterricht-todolist/src/App.jsx +++ b/react-unterricht-todolist/src/App.jsx @@ -15,6 +15,7 @@ function App() { }; setTodos((currentTodos) => [newTodo, ...currentTodos]); } + function toggleTodo(id) { setTodos((currentTodos) => currentTodos.map((todo) => @@ -22,6 +23,7 @@ function App() { ) ); } + function deleteTodo(id) { setTodos((currentTodos) => currentTodos.filter((todo) => todo.id !== id) diff --git a/react-unterricht-todolist/src/components/TodoForm.jsx b/react-unterricht-todolist/src/components/TodoForm.jsx index 3807924..0d2fce6 100644 --- a/react-unterricht-todolist/src/components/TodoForm.jsx +++ b/react-unterricht-todolist/src/components/TodoForm.jsx @@ -1,22 +1,30 @@ import { useState } from "react"; + function TodoForm({ onAddTodo }) { const [input, setInput] = useState(""); const [priority, setPriority] = useState("normal"); const [validationError, setValidationError] = useState(""); + function handleSubmit(event) { + event.preventDefault(); const cleanedInput = input.trim(); + if (cleanedInput === "") { setValidationError("Bitte geben Sie eine Aufgabe ein."); return; } + onAddTodo(cleanedInput, priority); + setInput(""); setPriority("normal"); setValidationError(""); } + return (
+
+
+