Skip to content

[URH-61] usePrefersColorScheme 신규 #51

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 1 commit into from
Aug 28, 2024

Conversation

Choozii
Copy link
Member

@Choozii Choozii commented Aug 20, 2024

👾 Pull Request

  • 상태: 신규

1️⃣ Spec

  • 사용자의 운영 체제의 색상 설정을 감지하는 훅
  • 다크모드일때는 'dark', 라이트모드일때는 'light'를 리턴

2️⃣ 변경 사항

3️⃣ 예시 코드

import usePrefersColorScheme from './hooks/usePrefersColorScheme';

function App() {
  const colorScheme = usePrefersColorScheme();
  console.log('dark mode', colorScheme === 'dark');
  return (
    <div>
      <h1>USE-REACT-HOOKS</h1>
    </div>
  );
}

export default App;

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

@Choozii Choozii self-assigned this Aug 20, 2024
@Choozii Choozii requested review from foresec and suhyeoonn August 20, 2024 14:37
export default usePrefersColorScheme;

const subscribeToMediaQuery = (callback: Fn) => {
if (!isClient || typeof window.matchMedia !== 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

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

[P4] 반복되는 !isClient || typeof window.matchMedia !== 'function' 체크 코드를 함수로 빼도 좋을 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

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

e23c234
여기에서 반영되었어요>.<

Copy link
Contributor

@suhyeoonn suhyeoonn left a comment

Choose a reason for hiding this comment

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

고생하셨습니다~! 저는 아직 useSyncExternalStore 훅이 익숙하지 않았는데, 지예님이 작업하신 코드를 분석하면서 많은 공부가 되었습니다!😊

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.

저도 useSyncExternalStore훅은 처음 접하는데, 리팩토링 기간이나 앞으로 개발에 적용해볼 수 있을 거같아서 굉장히 좋은 것 같습니다. 수고 많으셨습니다:)

✨ feat: 반복되는 코드 변수로 추출
@Choozii Choozii force-pushed the URH-61/use-prefers-color-scheme branch from e23c234 to ae025fa Compare August 28, 2024 08:11
@Choozii Choozii merged commit 1370e4b into master Aug 28, 2024
@Choozii Choozii deleted the URH-61/use-prefers-color-scheme branch August 28, 2024 08:12
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.

3 participants