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
7. 고차 함수와 렌더링 최적화 - 민정 #27
Closed
quokka-eating-carrots
wants to merge
20
commits into
REACTQUICKSTART-STUDY:develop
from
quokka-eating-carrots:develop
Closed
7. 고차 함수와 렌더링 최적화 - 민정 #27
quokka-eating-carrots
wants to merge
20
commits into
REACTQUICKSTART-STUDY:develop
from
quokka-eating-carrots:develop
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
7. 고차 함수와 렌더링 최적화
고차 함수 (higer-order function)
다른 함수와 컴포넌트를 인자로 전달받거나 리턴하는 함수.
{...props}
코드는 기존 컴포넌트가 사용하는 속성을 그대로 다시 전달하기 위해 반드시 작성.클래스 컴포넌트의 공통 로직을 분리하는 경우라면 고차 함수를 사용할 수밖에 없지만 함수 컴포넌트를 사용한다면 사용자 정의 훅을 작성하여 공통의 로직을 분리할 것을 권장.
React.memo 고차 함수
컴포넌트가 동일한 상태나 속성을 가지고 있다면 얕은 비교를 수행하도록 하여 불필요한 렌더링을 방지. 불변성을 가진 상태의 변경이 필수적.
React.memo(컴포넌트, (prevProps, nextProps) => {})
React.memo 고차 함수를 이용하면 렌더링 최적화가 가능. 전달받은 속성에 대해 이전 속성과 얕은 비교를 통해 다시 렌더링할지를 결정함으로써 렌더링 최적화를 한다. 함수를 속성으로 전달하는 경우 React.memo 고차 함수와 함게 useCallback 훅을 이용해 렌더링할 때마다 함수가 매번 생성되지 않도록 최적화할 수 있다.