diff --git a/src/App.js b/src/App.js index ce9cbd2..274b18d 100644 --- a/src/App.js +++ b/src/App.js @@ -1,26 +1,75 @@ -import React from 'react'; -import logo from './logo.svg'; -import './App.css'; +import React, { useState, useEffect } from 'react' +import axios from 'axios' + + +const useField = (type) => { + const [value, setValue] = useState('') + + const onChange = (event) => { + setValue(event.target.value) + } + + return { + type, + value, + onChange + } +} + +const useResource = (baseUrl) => { + const [resources, setResources] = useState([]) + + // ... + + const create = (resource) => { + // ... + } + + const service = { + create + } + + return [ + resources, service + ] +} + +const App = () => { + const content = useField('text') + const name = useField('text') + const number = useField('text') + + const [notes, noteService] = useResource('http://localhost:3005/notes') + const [persons, personService] = useResource('http://localhost:3005/persons') + + const handleNoteSubmit = (event) => { + event.preventDefault() + noteService.create({ content: content.value }) + } + + const handlePersonSubmit = (event) => { + event.preventDefault() + personService.create({ name: name.value, number: number.value}) + } -function App() { return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+
+

notes

+
+ + +
+ {notes.map(n =>

{n.content}

)} + +

persons

+
+ name
+ number + +
+ {persons.map(n =>

{n.name} {n.number}

)}
- ); + ) } -export default App; +export default App \ No newline at end of file