Skip to content

Feature/use unmount 추가 #14

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

Merged
merged 8 commits into from
Jul 20, 2024
Merged

Feature/use unmount 추가 #14

merged 8 commits into from
Jul 20, 2024

Conversation

Choozii
Copy link
Member

@Choozii Choozii commented Jul 12, 2024

👾 Pull Request

  • 작업명: use-unmount
  • 상태:신규

1️⃣ Spec

  • 컴포넌트가 unmount 될 때 전달받은 함수를 실행

2️⃣ 변경 사항

3️⃣ 예시 코드

import React, { useState, useCallback } from 'react';
import useUnmount from './useUnmount';

const ExampleComponent = () => {

  useUnmount(() => {
    console.log(`이 함수는 ExampleComponent가 unMount될 때 실행됩니다.`)
  });

  return (
    <div>...</div>
  );
};

export default ExampleComponent;

4️⃣ 관련 문서 (선택 사항)

@Choozii Choozii self-assigned this Jul 12, 2024
@Choozii Choozii requested review from bicochan and foresec July 12, 2024 15:01
* @param callback 언마운트 시에 호출될 함수
*/

const useUnmount = (callback: () => void) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useUnmountCallback, useUnmountEffect

[P2] 훅의 역할이 좀 더 명확하게 드러나도록 위와 같이 이름을 지어보는 건 어떨까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 생각이에유! useUnmountEffect가 더 와닿는 이름인것 같아서 그걸로 초이스하겠습니다~.~
b925359에서 변경되었어요!

return () => {
if (callbackRef.current) {
callbackRef.current();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callbackRef.current = null;

[P2] 클린업 단계에서 callbackRef를 초기화시키는 건 어떨까요? 메모리 누수를 방지할 수 있을 것 같습니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10eb498에서 수정되었습니다!

Copy link
Collaborator

@foresec foresec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다! 자주 쓰일 훅이네요:)

Copy link
Member

@jeongbaebang jeongbaebang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멋진 훅이네요 고생하셨습니다!

@Choozii Choozii merged commit cac14d6 into master Jul 20, 2024
@Choozii Choozii deleted the feature/use-unmount branch July 20, 2024 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants