continue lesson
This commit is contained in:
parent
f1916e5c56
commit
f1b67a4346
2 changed files with 15 additions and 8 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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 />);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue