// data의 길이가 변할 때만 연산 최적화
const getDiaryAnalysis = useMemo(() => {
console.log("일기 분석 시작");
const goodCount = data.filter((it) => it.emotion >= 3).length;
const badCount = data.length - goodCount;
const goodRatio = (goodCount / data.length) * 100;
return { goodCount, badCount, goodRatio };
}, [data.length]);
// useMemo로부터 값을 반환 받기 때문에 함수를 호출하면 안 된다.
const { goodCount, badCount, goodRatio } = getDiaryAnalysis;