Skip to content

Commit

Permalink
63.프로젝트 최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
braverokmc79 committed Nov 16, 2022
1 parent 460308e commit edc054f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Expand Up @@ -112,7 +112,7 @@ function App() {
if (localData) {
const diaryList = JSON.parse(localData).sort((a, b) => parseInt(b.id) - parseInt(a.id));
dataId.current = parseInt(diaryList[0].id) + 1;
console.log(" dataId.current : ", dataId.current);
// console.log(" dataId.current : ", dataId.current);
dispatch({ type: "INIT", data: diaryList });
}

Expand Down
7 changes: 4 additions & 3 deletions src/components/DiaryEditor.js
@@ -1,4 +1,4 @@
import React, { useState, useRef, useContext, useEffect } from 'react';
import React, { useState, useRef, useContext, useEffect, useCallback } from 'react';
import MyHeader from './MyHeader';
import MyButton from './MyButton';
import { useNavigate } from 'react-router-dom';
Expand All @@ -23,9 +23,10 @@ const DiaryEditor = ({ isEdit, originData }) => {
const navigate = useNavigate();
const { onCreate, onEdit, onRemove } = useContext(DiaryDispatchContext);

const handleClickEmote = (emotion) => {
const handleClickEmote = useCallback((emotion) => {
setEmotion(emotion);
}
}, []);


const hadnleSubmit = () => {
if (content.length < 1) {
Expand Down
3 changes: 1 addition & 2 deletions src/components/DiaryItem.js
Expand Up @@ -6,7 +6,6 @@ import { useNavigate } from 'react-router-dom';

const DiaryItem = ({ id, content, emotion, date }) => {
const navigate = useNavigate();

const env = process.env;
env.PUBLIC_URL = env.PUBLIC_URL || "";

Expand Down Expand Up @@ -40,4 +39,4 @@ const DiaryItem = ({ id, content, emotion, date }) => {
);
};

export default DiaryItem;
export default React.memo(DiaryItem);
5 changes: 3 additions & 2 deletions src/components/DiaryList.js
Expand Up @@ -14,7 +14,8 @@ const filterOptionList = [
{ value: "bad", name: "안좋은 감정만" },
]

const ControlMenu = ({ value, setOnChange, optionList }) => {
const ControlMenu = React.memo(({ value, setOnChange, optionList }) => {
//console.log("ControlMenu");
return <select
className='ControlMenu'
value={value} onChange={(e) => setOnChange(e.target.value)} >
Expand All @@ -23,7 +24,7 @@ const ControlMenu = ({ value, setOnChange, optionList }) => {
(<option key={idx} value={it.value}>{it.name}</option>))
}
</select>
}
})

const DiaryList = ({ diaryList }) => {
const navigate = useNavigate();
Expand Down
8 changes: 5 additions & 3 deletions src/components/EmotionItem.js
@@ -1,6 +1,8 @@
import { useState } from 'react';
import React, { useState } from 'react';

const EmotionItem = ({ emotion_id, emotion_img, emotion_descript, onClick, isSelected }) => {
const EmotionItem = ({ emotion_id, emotion_img,
emotion_descript,
onClick, isSelected }) => {



Expand All @@ -13,4 +15,4 @@ const EmotionItem = ({ emotion_id, emotion_img, emotion_descript, onClick, isSel
</div>
};

export default EmotionItem;
export default React.memo(EmotionItem);
2 changes: 1 addition & 1 deletion src/components/MyButton.js
Expand Up @@ -11,4 +11,4 @@ const MyButton = ({ text, type, onClick }) => {
);
};

export default MyButton;
export default React.memo(MyButton);
2 changes: 1 addition & 1 deletion src/components/MyHeader.js
Expand Up @@ -16,4 +16,4 @@ const MyHeader = ({ headText, leftChild, rightChild }) => {
);
};

export default MyHeader;
export default React.memo(MyHeader);

0 comments on commit edc054f

Please sign in to comment.