continue lesson

This commit is contained in:
counterweight 2025-05-25 14:19:20 +02:00
parent f1916e5c56
commit f1b67a4346
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 15 additions and 8 deletions

View file

@ -1,11 +1,23 @@
import { useState } from "react";
import { useState, useEffect } from "react";
import axios from "axios";
import Note from "./components/Note";
const App = ({ startingNotes }) => {
const App = ({ startingNotes = [] }) => {
const [notes, setNotes] = useState(startingNotes);
const [newNote, setNewNote] = useState("a new note...");
const [showAll, setShowAll] = useState(true);
useEffect(() => {
console.log("effect");
axios.get("http://localhost:3001/notes").then((response) => {
console.log("promise fulfilled");
setTimeout(() => {
setNotes(response.data);
}, 2000);
});
}, []);
console.log("render", notes.length, "notes");
const addNote = (event) => {
event.preventDefault();
const newNoteObject = {

View file

@ -3,9 +3,4 @@ import App from "./App";
import axios from "axios";
axios.get("http://localhost:3001/notes").then((response) => {
const notes = response.data;
ReactDOM.createRoot(document.getElementById("root")).render(
<App startingNotes={notes} />
);
});
ReactDOM.createRoot(document.getElementById("root")).render(<App />);