Loading Now...
;
+ } else {
+ return (
+
+ {Object.keys(data).map((key) => (
+
+ {key} : {data[key]}
+
+ ))}
+
+ );
+ }
};
export default DetailPage;
diff --git a/src/MainPage/Main.tsx b/src/MainPage/Main.tsx
index 9ee6bdf..34debb8 100644
--- a/src/MainPage/Main.tsx
+++ b/src/MainPage/Main.tsx
@@ -1,5 +1,4 @@
import React, { useEffect, useReducer, useRef, useState } from "react";
-import { memo } from "../App";
import SideBar from "../CommonPage/SideBar/SideBar";
import "./Main.css";
import MemoList from "./MemoList";
@@ -7,102 +6,30 @@ import TodoTemplete from "./TodoList/TodoTemplete";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faClipboardList } from "@fortawesome/free-solid-svg-icons";
import { faCalendarDays } from "@fortawesome/free-solid-svg-icons";
-import DetailPage from "../DetailPage/DetailPage";
-
-const reducer = (state: any, action: any) => {
- let newState = [];
- switch (action.type) {
- case "INIT": {
- return action.data;
- }
- case "CREATE": {
- newState = [...state, action.data];
- break;
- }
- case "REMOVE": {
- newState = state.filter((it) => it.id !== action.targetId);
- break;
- }
- case "EDIT": {
- newState = state.map((it) => {
- return it.id === action.data.id ? { ...action.data } : it;
- });
- break;
- }
- default:
- return state;
- }
- return newState;
-};
-
-export const MemoStateContext = React.createContext<[]>([]);
-export const MemoDispatchContext = React.createContext<{}>({});
const MainPage = ({ memoData }) => {
const [addTodo, setAddTodo] = useState(false);
- const [data, dispatch] = useReducer(reducer, memoData);
- const dataId = useRef(4);
-
- useEffect(() => {
- if (data) {
- dispatch({ type: "INIT", data: data });
- }
- }, [data]);
-
- const onCreate = () => {
- dispatch({
- type: "CREATE",
- data: {
- id: dataId.current,
- title: "메모장 이름",
- date: "지정 날짜",
- description: "메모장 소개",
- color: 0,
- },
- });
- dataId.current += 1;
- };
-
- const onRemove = (targetId) => {
- dispatch({ type: "REMOVE", targetId });
- };
-
- const onEdit = (targetId, title, date, description, color) => {
- dispatch({
- type: "EDIT",
- data: {
- id: targetId,
- title,
- date,
- description,
- color,
- },
- });
- };
return (