Skip to content
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

[Feature]: useAsyncBoundaryProvider의 값이 null인 경우 assert를 사용해서 Provider로 감싸 달라는 메시지를 던지는게 좋지 않나요? #498

Open
1 task
gihwan-dev opened this issue Jun 20, 2024 · 0 comments

Comments

@gihwan-dev
Copy link

Package Scope

  • [x ] Add to an existing package
  • New package

Package name: react/async-boundary/src/provider/AsyncBoundaryProvider.tsx

Overview

useAsyncBoundaryContext 훅에서 useContext(AsyncBoundaryContext) 값이 null 인 경우 { resetKey: null, reset: () => {} }; 를 반환하는걸 봤습니다. 이렇게 한 이유가 뭔지 궁금합니다!

이 값이 null인 경우가 AsyncBoundaryProvider로 감싸지 않았을 경우 밖에 생각나지 않는데 그렇다면 AsyncBoundaryProvider 내부에서만 useAsyncBoundaryContext를 사용할 수 있다는 메시지를 던지는게 좋지 않나? 하는 생각입니다!

만약 그런 처리 없이 사용했을 때 필요한 컨텍스트가 없으면 { resetKey: null, reset: () => {} } 값을 받아 사용하게 되는데 디버깅에 어려움을 주게 되지 않을까 하는 생각이 들었습니다.

Describe the solution you'd like

기존

export function useAsyncBoundaryContext() {
  return useContext(AsyncBoundaryContext) ?? { resetKey: null, reset: () => {} };
}

변경

export function useAsyncBoundaryContext() {
  const context = useContext(AsyncBoundaryContext);

  if (!context) {
    assert("useAsyncBoundaryContext should be used in wrapped Component with AsyncBoundaryProvider");
  }

  return context;
}

Additional context

만약 에러를 던지지 않고 더미 값을 반환하는 동작이 의도되었다면 그 이유가 궁금합니다!

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

No branches or pull requests

1 participant