Exercise 2.11

This commit is contained in:
Augusto Gunsch 2022-06-15 18:06:09 +02:00
parent 13439e412f
commit 9bd291a245
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
5 changed files with 3002 additions and 4084 deletions

24
part2/phonebook/db.json Normal file
View File

@ -0,0 +1,24 @@
{
"persons":[
{
"name": "Arto Hellas",
"number": "040-123456",
"id": 1
},
{
"name": "Ada Lovelace",
"number": "39-44-5323523",
"id": 2
},
{
"name": "Dan Abramov",
"number": "12-43-234345",
"id": 3
},
{
"name": "Mary Poppendieck",
"number": "39-23-6423122",
"id": 4
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.16.4", "@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0", "@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"react": "^18.1.0", "react": "^18.1.0",
"react-dom": "^18.1.0", "react-dom": "^18.1.0",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
@ -15,7 +16,8 @@
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject",
"server": "json-server -p3001 --watch db.json"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
@ -34,5 +36,8 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"devDependencies": {
"json-server": "^0.17.0"
} }
} }

View File

@ -1,4 +1,5 @@
import { useState } from 'react' import { useState, useEffect } from 'react'
import axios from 'axios'
import Filter from './components/Filter' import Filter from './components/Filter'
import Form from './components/Form' import Form from './components/Form'
@ -6,12 +7,11 @@ import Numbers from './components/Numbers'
const App = () => { const App = () => {
const [filter, setFilter] = useState('') const [filter, setFilter] = useState('')
const [persons, setPersons] = useState([ const [persons, setPersons] = useState([])
{ name: 'Arto Hellas', number: '040-123456', id: 1 },
{ name: 'Ada Lovelace', number: '39-44-5323523', id: 2 }, useEffect(() => axios
{ name: 'Dan Abramov', number: '12-43-234345', id: 3 }, .get('http://localhost:3001/persons')
{ name: 'Mary Poppendieck', number: '39-23-6423122', id: 4 } .then(response => setPersons(response.data)), []);
])
return ( return (
<div> <div>

View File

@ -1,4 +1,4 @@
import React from 'react'; import * as React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import App from './App'; import App from './App';