diff --git a/simplediary/src/App.js b/simplediary/src/App.js index e8e036dc..963c727a 100644 --- a/simplediary/src/App.js +++ b/simplediary/src/App.js @@ -1,36 +1,56 @@ +import React, { useRef, useState } from "react"; import "./App.css"; import DiaryEditor from "./DiaryEditor"; import DiaryList from "./DiaryList"; -const dummyList = [ - { - id: 1, - author: "kim", - content: "hihi", - emotion: 5, - created_date: new Date().getTime(), - }, - { - id: 2, - author: "lee", - content: "hihi", - emotion: 2, - created_date: new Date().getTime(), - }, - { - id: 3, - author: "park", - content: "hihi", - emotion: 4, - created_date: new Date().getTime(), - }, -]; +// const dummyList = [ +// { +// id: 1, +// author: "kim", +// content: "hihi", +// emotion: 5, +// created_date: new Date().getTime(), +// }, +// { +// id: 2, +// author: "lee", +// content: "hihi", +// emotion: 2, +// created_date: new Date().getTime(), +// }, +// { +// id: 3, +// author: "park", +// content: "hihi", +// emotion: 4, +// created_date: new Date().getTime(), +// }, +// ]; const App = () => { + const [data, setData] = useState([]); + + const dataId = useRef(0); + + const onCreate = (author, content, emotion) => { + const created_date = new Date().getTime(); + + const newItem = { + author, + content, + emotion, + created_date, + id: dataId.current, + }; + dataId.current += 1; + + setData([newItem, ...data]); + }; + return (