diff --git a/part7/routed-anecdotes/src/App.js b/part7/routed-anecdotes/src/App.js index f648cbf..0dac343 100644 --- a/part7/routed-anecdotes/src/App.js +++ b/part7/routed-anecdotes/src/App.js @@ -1,4 +1,5 @@ import { useState } from "react"; +import { useField } from "./hooks/hooks"; import { Route, Routes, Link, useMatch, useNavigate } from "react-router-dom"; const Menu = () => { @@ -37,7 +38,7 @@ const Anecdote = ({ anecdote }) => (
has {anecdote.votes} votes
- for more info see {anecdote.info} + for more info see here
); @@ -90,51 +91,46 @@ const Footer = () => ( const CreateNew = (props) => { const navigate = useNavigate(); - const [content, setContent] = useState(""); - const [author, setAuthor] = useState(""); - const [info, setInfo] = useState(""); + const { reset: contentReset, ...content } = useField("content"); + const { reset: authorReset, ...author } = useField("author"); + const { reset: infoReset, ...info } = useField("info"); const handleSubmit = (e) => { e.preventDefault(); props.addNew({ - content, - author, - info, + content: content.value, + author: author.value, + info: info.value, votes: 0, }); navigate("/"); }; + const handleReset = () => { + contentReset(); + authorReset(); + infoReset(); + }; + return (