// useMemo 사용
return useMemo(() => ((...args) => callbackRef.current?.(...args)) as T, []);
// useCallback 사용
// eslint-disable-next-line react-hooks/exhaustive-deps
return useCallback(((...args) => callbackRef.current?.(...args)) as T, []);
react 공식문서를 참고하자면useMemo를 써도, useCallback을 써도 목적은 함수 자체를 캐싱하기 위한 것이기 때문에 위 두 코드는 같은 결과를 뱉습니다. useCallback을 쓴 경우 위와 같이 eslint react-hooks/exhaustive-deps 규칙에 경고가 나오기 때문에 피하기 위해 useMemo를 사용하였습니다.
이슈 번호
작업한 목록을 작성해 주세요
스크린샷
pr 포인트나 궁금한 점을 작성해 주세요
useMemo
를 써도,useCallback
을 써도 목적은 함수 자체를 캐싱하기 위한 것이기 때문에 위 두 코드는 같은 결과를 뱉습니다. useCallback을 쓴 경우 위와 같이 eslintreact-hooks/exhaustive-deps
규칙에 경고가 나오기 때문에 피하기 위해useMemo
를 사용하였습니다.