Skip to content

Commit

Permalink
feat: Fetch and display notes from server in App component
Browse files Browse the repository at this point in the history
  • Loading branch information
rashmikanaveen committed Sep 4, 2024
1 parent 649bf1b commit 0397aab
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions part1/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import { useState } from 'react'
import { useState,useEffect } from 'react'
import Note from './components/Note'
import axios from 'axios'

const App = (props) => {
const [notes, setNotes] = useState(props.notes)
const App = () => {
const [notes, setNotes] = useState([])

const [newNote, setNewNote] = useState('a new note...')
const [showAll, setShowAll] = useState(true)

useEffect(() => {
console.log('effect')

const eventHandler = response => {
console.log('promise fulfilled')
setNotes(response.data)
}

const promise = axios.get('http://localhost:3001/notes')
promise.then(eventHandler)
}, [])


const handleNoteChange = (event) => {
console.log(event.target.value)
setNewNote(event.target.value)
Expand Down

0 comments on commit 0397aab

Please sign in to comment.