Skip to content

Commit

Permalink
add update page component
Browse files Browse the repository at this point in the history
  • Loading branch information
k-nasa committed Aug 14, 2019
1 parent 9886f04 commit 3be6198
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import firebase from "./firebase";
import { AddArticle } from "./pages/add_article";
import IndexArticle from "./pages/index_article";
import ShowArticle from "./pages/show_article";
import UpdateArticle from "./pages/update_article";
import { getPrivateMessage } from "./api";
import { useState, useEffect } from "react";
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
Expand Down
29 changes: 29 additions & 0 deletions src/pages/update_article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";
import { useState, useEffect } from "react";
import { getArticle } from "../api";

const UpdateArticle = props => {
const [article, setArticle] = useState({});
const [title, setTitle] = useState("")
const [body, setBody] = useState("")

useEffect(() => {
const id = props.p.match.params.id;

getArticle(id).then(resp => {
setArticle(resp.Article);
setTitle(resp.Article.title)
setBody(resp.Article.body);
});
}, []);

return (
<div>
<input type="text" value={title} onChange={(e) => setTitle(e.target.value)}/>
<textarea value={body} onChange={(e) => setBody(e.target.value)} />
<input type="submit" />
</div>
);
};

export default UpdateArticle;

0 comments on commit 3be6198

Please sign in to comment.