useMemo관련 질문드립니다
import React, { useCallback, useMemo } from "react";
import "../List.css";
import TodoItem from "./TodoItem";
import { useState } from "react";
const List = ({ todos, onUpdate, onDelete }) => {
const [search, setSearch] = useState("");
console.log(todos);
const onChangeSearch = (e) => {
setSearch(e.target.value);
};
const getFilteredData = () => {
if (search === "") {
return todos;
} else {
return todos.filter((todo) =>
todo.content.toLowerCase().includes(search.toLowerCase())
);
}
};
const filteredTodos = getFilteredData();
const getAnalyedData = () => {
console.log("getAnalyedData");
const totalCount = todos.length;
const doneCount = todos.filter((todo) => todo.isDone).length;
const notDoneCount = totalCount - doneCount;
return {
totalCount,
doneCount,
notDoneCount,
};
};
const analyzedData = useMemo(() => {
return getAnalyedData();
}, [todos]);
return (
<div className="List">
<div className="GetAnalyedData">
<h1>total :::{analyzedData.totalCount}</h1>
<h1>done :::{analyzedData.doneCount}</h1>
<h1>notDone:::{analyzedData.notDoneCount}</h1>
</div>
<h4>검색어</h4>
<input
placeholder="검색어 입력"
onChange={onChangeSearch}
value={search}
/>
<div className="todos_wrapper">
{filteredTodos.map((todo) => {
return (
<TodoItem
key={todo.id}
{...todo}
onUpdate={onUpdate}
onDelete={onDelete}
/>
);
})}
</div>
</div>
);
};
export default List;
const getAnalyedData = () => {
console.log("getAnalyedData");
const totalCount = todos.length;
const doneCount = todos.filter((todo) => todo.isDone).length;
const notDoneCount = totalCount - doneCount;
return {
totalCount,
doneCount,
notDoneCount,
};
};
const analyzedData = useMemo(() => {
return getAnalyedData();
}, [todos]);이런식으로 넣어도 혹시 가능할까요 ???
Line 36:6: React Hook useMemo has a missing dependency: 'getAnalyedData'. Either include it or remove the dependency array react-hooks/exhaustive-deps
이런 에러가 떠서요 ..기능은 돌던데
답변 1
0
안녕하세요 이정환입니다.
네 문제 없습니다. 결론적으로 todos 데이터에 변화가 생겼을 때에만 동작시키게 되니까요 😃
추가로 Lint 경고 메세지는 강의중 안내드렸듯 무시하셔도 괜찮습니다!
Editor Component의 최적화 불가능 이슈
0
39
2
useCallback ⊂ useMemo
0
38
2
라이브러리 설치 질문
0
34
2
linter 질문
0
41
2
감정일기장 vercel 배포 후 새로 고침 시 404페이지가 뜨는 이유
0
42
2
Sort 메서드 관련 아티클
0
44
2
4.1) React.js를 소개합니다 강의를 듣고 궁금한 점이 생겼습니다.
0
46
2
html, body에 적용하는 css 스타일 질문입니다.
0
42
2
eslint.config.js 설정 질문입니다.
0
95
2
존재하지 않는 일기 url입력 시 alert이 두 번 떠요
0
70
1
교재(3쇄)와 강의 내용 문의
0
69
2
12.13) 하단 여백 스타일링 관련 질문 드립니다.
0
91
2
에러 질문드립니다
0
109
2
VSCode 설정 문의
0
142
2
PPT 코드 관련 질문
0
67
2
useEffect와 lifecycle문의
0
89
2
프론트엔드 학습 수준 문의
0
110
2
리액트 챕터별 코드에서 eslint 설정파일이 없어요
0
112
2
데이터 로딩중 화면만 계속 나와요!!
0
102
2
퍼블리셔일경우 어느정도 수준까지 강의를 들어야할까요
0
134
2
이후의 커리큘럼 문의
0
156
2
실슬환경 설정에서 save후 console.log 부분이 새로고침이 안되는현상입니다.
0
114
2
최적화 관련 질문있습니다 (useMemo 등)
0
134
3
프로바이더 컴포넌트의 위치는 어떤 기준인가요?
1
129
3





