-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Hook 간단 #31
Comments
useEffect에서 Clean-up 함수 사용하기useEffect(() => {
...
return () => {
// 여기의 코드는, 라이프사이클이 돌아가면서 useEffect가 새로 실행되기 이전에 실행됨
};
}); 그러니까 state가 새로 바뀔 때, 직전의 state에 대한 처리를 저기서 할 수 있음 |
useRef로 이전 state의 값 기억하기const prevValueRef = useRef();
const prevValue = prevValueRef.current;
useEffect(() => {
console.log('value updated:', prevValue, '->', value);
}); const inProgressTasks = List(store.get('task_list').filter(each => !each.completed));
const prevInProgressTasks = useRef(List());
useEffect(() => {
prevInProgressTasks.current = inProgressTasks;
}, [inProgressTasks]); |
useEffect(() => {
console.log('value updated:', prevValue, '->', value);
}, []); // 이 코드는 한 번만 실행됨 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: