-
Notifications
You must be signed in to change notification settings - Fork 47
[4팀 정한슬] Chapter3-2. 디자인 패턴과 함수형 프로그래밍 그리고 상태 관리 설계 #38
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
Open
hanseul524
wants to merge
24
commits into
hanghae-plus:main
Choose a base branch
from
hanseul524:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
과제의 핵심취지
과제에서 꼭 알아가길 바라는 점
기본과제
Component에서 비즈니스 로직을 분리하기
비즈니스 로직에서 특정 엔티티만 다루는 계산을 분리하기
뷰데이터와 엔티티데이터의 분리에 대한 이해
entities -> features -> UI 계층에 대한 이해
Component에서 사용되는 Data가 아닌 로직들은 hook으로 옮겨졌나요?
주어진 hook의 책임에 맞도록 코드가 분리가 되었나요?
계산함수는 순수함수로 작성이 되었나요?
Component에서 사용되는 Data가 아닌 로직들은 hook으로 옮겨졌나요?
주어진 hook의 책임에 맞도록 코드가 분리가 되었나요?
계산함수는 순수함수로 작성이 되었나요?
특정 Entitiy만 다루는 함수는 분리되어 있나요?
특정 Entitiy만 다루는 Component와 UI를 다루는 Component는 분리되어 있나요?
데이터 흐름에 맞는 계층구조를 이루고 의존성이 맞게 작성이 되었나요?
심화과제
이번 심화과제는 Context나 Jotai를 사용해서 Props drilling을 없애는 것입니다.
어떤 props는 남겨야 하는지, 어떤 props는 제거해야 하는지에 대한 기준을 세워보세요.
Context나 Jotai를 사용하여 상태를 관리하는 방법을 익히고, 이를 통해 컴포넌트 간의 데이터 전달을 효율적으로 처리할 수 있습니다.
Context나 Jotai를 사용해서 전역상태관리를 구축했나요?
전역상태관리를 통해 domain custom hook을 적절하게 리팩토링 했나요?
도메인 컴포넌트에 도메인 props는 남기고 props drilling을 유발하는 불필요한 props는 잘 제거했나요?
전체적으로 분리와 재조립이 더 수월해진 결합도가 낮아진 코드가 되었나요?
과제 셀프회고
https://hanseul524.github.io/front_7th_chapter3-2/
굉장히 시간이 많이 들고 고민을 많이 하게 되는 과제 였습니다. basic을 진행할 때 부터 뭔가 명확하게 제 자신 스스로 기준이 안서는것 같아서 이랬다 저랬다 하면서 찾아갔던 것 같습니다 ... 일단 기준을 뚜렷하게 세운 뒤 그 기준을 따라가야 길을 잃지 않고 과제를 할 수 있다고 생각했습니다 ^^ .. 저는 사실 전역 상태관리를 써본적이 없어서 basic이 제가 공부했던 디폴트 값이였는데 advanced를 하면서 역체감을 하게 되서 공부가 많이 됬습니다.
폴더구조
힌트로 주신 구조를 기반으로 추가로 필요한 폴더를 추가하는 방식으로 진행했습니다. 페이지 컴포넌트와 재사용 가능한 컴포넌트를 분리해 페이지 → 하위 컴포넌트가 함께 위치하도록 했습니다.
이렇게 하면 페이지 수정 시 파일을 찾기 쉽고 해당 페이지에 기능 추가시 컴포넌트 파일의 위치가 명확해집니다.
계층별 책임분리
각 계층은 명확한 단일 책임만 가지도록 분리했습니다.
1. App.tsx - 상태 통합 계층
2. Pages - 페이지 조합 계층
3. Components - UI 표시 계층
4. Hooks - 비즈니스 로직 계층
5. Models - 순수 계산 함수 계층
의존성 방향
전역 상태 관리 전환
리액트를 사용하면서 전역 상태 관리 .. 라는 것을 처음 사용해보고 그 개념에 대해 잘 이해하지 못하다가 처음부터 사용해보면서 Custom Hooks + Props Drilling 방식에서 Zustand 전역 상태 관리로의 전환을 통해서 조금은 감을 잡은 것 같습니다.
문제점
처음
App.tsx에서 store를 직접 사용하는 방식을 사용했습니다. props driling을 없애기 위해 전역 상태 관리를 사용하는 건데 똑같은 현상이 일어나고 있어서 각 컴포넌트에서 필요한 store를 가져오는 방식으로 변경했습니다ㅠㅠ .. 지금 생각하니까 완전 바보같은 실수였습니다.과제를 하면서 내가 알게된 점, 좋았던 점은 무엇인가요?
Zustand와 Custom Hook의 차이점 체감
Zustand Persist의 동작 원리 이해
{state: {...}, version: 0}형식으로 저장한다는 것을 알게 되었습니다.Store 분리와 조합의 중요성
Hook 분리 기준에 대한 명확한 이해
useProductForm같은 Hook을 만들 뻔 했지만, 이는 과도한 추상화라는 것을 알게 되었습니다. 특수한 상황에서만 사용되기 때문에 이런 상황에서는 컴포넌트 내부에서 구현하는 것이 나은 방법이라는것을 알게되었습니다.순수 함수의 힘
calculateCartTotal,getMaxApplicableDiscount같은 순수 함수를 분리하니 테스트가 쉬워지고 코드의 의도가 명확해졌습니다.컴포넌트 분리의 실용성
ProductForm,CouponForm은 각자의 validation 로직을 가지고 있어 분리하는 것이 맞았고,Button,Input같은 UI 컴포넌트는 재사용성이 높아 분리가 필수였습니다.Props Drilling의 필요성 인식
이번 과제에서 내가 제일 신경 쓴 부분은 무엇인가요?
1. 명확한 기준 세우기
✅ Hook으로 분리해야 하는 경우
안티패턴 예시:
올바른 패턴:
2. 데이터 흐름의 단방향성
addNotification을 props로 전달하는 방식을 선택한 이유를 문서화했습니다.3. 과도한 추상화 지양
useProductForm,useAdminTabs같은 Hook을 만들 뻔 했지만, 재사용되지 않는 로직은 Hook으로 만들지 않았습니다.이번 과제를 통해 앞으로 해보고 싶은게 있다면 알려주세요!
리뷰 받고 싶은 내용이나 궁금한 것에 대한 질문 편하게 남겨주세요 :)