#14CouplingMedium

God Hook (useUser) → Split by Concern

God Hook — 한 hook이 모든 걸 관리

useUser hook 안에 user 프로필, preferences, notifications, friends, posts, messages 가 모두 들어 있습니다. 하나의 작은 변경 (예: notification 마크 읽기) 이 모든 user 사용처 의 리렌더를 트리거. 또 friend 기능을 안 쓰는 컴포넌트도 friend fetch 비용을 같이 짊어짐.

할 일

관심사별로 hook을 분리하세요:

  • useCurrentUser() — user, loading, error
  • useUserPreferences(userId) — preferences, updatePreferences
  • useUserNotifications(userId) — notifications, markNotificationRead
  • useUserMessages(userId) — messages, sendMessage

각 hook은 자기 데이터만 fetch + 관리. 호출하는 컴포넌트는 필요한 hook만 가져다 쓰면 됨.

좋은 fix

  • 도메인별로 분리 (auth / preferences / notifications / messages)
  • 각 hook은 자기 fetch effect만 가짐

안 되는 fix

  • 안에서 상태만 분리하고 한 hook이 다 wrapping (실제로는 그대로)
  • 분리는 했는데 useUser 가 내부에서 모두 호출 (의존 그래프 그대로)
Sandpack 로드 중…