Skip to content

[Step2.2] hippo: Zustand 적용하기 - #5

Open
meteorqz6 wants to merge 9 commits into
hippo-adv-2.1from
hippo-adv-2.2
Open

[Step2.2] hippo: Zustand 적용하기#5
meteorqz6 wants to merge 9 commits into
hippo-adv-2.1from
hippo-adv-2.2

Conversation

@meteorqz6

@meteorqz6 meteorqz6 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

개인 목표 달성 여부

  • Context API로 구현된 앱을 Zustand로 마이그레이션하면서 두 방식의 차이를 체감한다.
  • create, set, get, selector 개념을 직접 사용하며 Zustand 스토어 구조를 익힌다.
  • 전역 상태로 관리할 것과 로컬 상태로 유지할 것을 스스로 판단하는 능력을 기른다.

Summary by CodeRabbit

  • 새 기능

    • 전역 상태 관리를 Zustand 기반으로 전환하고, 음식점 목록과 카테고리 선택 상태를 더 안정적으로 관리할 수 있게 했습니다.
    • 카테고리 선택 값은 새로고침 후에도 유지되도록 개선했습니다.
  • 변경 사항

    • 음식점 추가, 목록 조회, 로딩/오류 처리 흐름이 새 상태 관리 방식에 맞게 정리되었습니다.
    • 관련 안내 문서와 학습 가이드가 새로운 상태 관리 방식 중심으로 업데이트되었습니다.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 7e5e9b53-97a7-42d9-945d-3947a440f7d2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Context API 기반의 RestaurantsContext, RestaurantsProvider, useRestaurantsContext, useRestaurants 훅을 제거하고, Zustand create + persist 미들웨어로 구성한 useRestaurantStore로 전역 상태를 대체했다. App, RestaurantList, AddRestaurantModal 컴포넌트가 스토어에 직접 연결되었으며, selectedCategorylocalStorage에 persist된다.

Changes

Context API → Zustand 전역 상태 마이그레이션

Layer / File(s) Summary
Zustand 스토어 생성 및 persist 설정
package.json, src/store/useRestaurantStore.js
zustand 의존성 추가. useRestaurantStorecreate + persist로 정의하고 restaurants, isLoading, error, selectedCategory 상태와 fetchRestaurants(try/catch/finally), addRestaurant(완료 후 목록 재조회), setSelectedCategory 액션을 구현. persistselectedCategory"restaurant-storage"에 저장.
Context API 코드 제거 및 App 연결
src/context/RestaurantsContext.jsx, src/context/useRestaurantsContext.js, src/hooks/useRestaurants.js, src/App.jsx
RestaurantsContext, RestaurantsProvider, useRestaurantsContext, useRestaurants 훅 전체 삭제. App에서 selectedCategory/setSelectedCategoryuseState에서 useRestaurantStore로 전환하고 RestaurantsProvider 래퍼를 fragment로 교체.
컴포넌트 스토어 연결
src/components/RestaurantList.jsx, src/components/AddRestaurantModal.jsx
RestaurantListuseRestaurantStore selector로 restaurants/isLoading/error/fetchRestaurants를 읽고 useEffect에서 마운트 시 fetchRestaurants() 호출. AddRestaurantModal은 스토어에서 addRestaurant를 가져오도록 전환.
README 문서 업데이트
README.md, 02-state-management-tools/2.2-Zustand/README.md
과제 README 신규 추가. 학습 README가 Context API 설명에서 Zustand 핵심 개념 표·코드 예시·비교·회고 구조로 전면 개편.

예상 코드 리뷰 노력

🎯 2 (Simple) | ⏱️ ~10 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@meteorqz6 meteorqz6 self-assigned this Jun 27, 2026
@meteorqz6

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@meteorqz6 meteorqz6 changed the title Hippo adv 2.2 [Step2.2] hippo: Zustand 적용하기 Jun 27, 2026
{
name: "restaurant-storage",
partialize: (state) => ({ selectedCategory: state.selectedCategory }),
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[제안]
카테고리 필터는 브라우저를 닫아도 유지해야 하는 설정값보다 현재 탐색 중인 임시 상태에 가깝다고 판단해서 저는 sessionStorage로 변경했습니다. localStorage는 탭 간에도 공유되고 브라우저를 닫아도 남아있기 때문에, 이 경우엔 sessionStorage를 사용하는 것이 더 적합할 것 같습니다!

}),
{
name: "restaurant-storage",
partialize: (state) => ({ selectedCategory: state.selectedCategory }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[배움]
저는 서버 데이터와 카테고리 필터를 각각 다른 store로 분리했는데, partialize를 사용하면 단일 store를 유지하면서도 저장할 상태를 선택할 수 있군요. 두 방식 모두 서버 데이터가 localStorage에 저장되는 걸 방지한다는 점에서 같은 문제를 해결하고 있는데, partialize를 쓰면 파일 수를 줄일 수 있어서 더 간결해 보여요.

Comment thread README.md
```

### AddRestaurantModal — onSubmit prop 제거
### 이벤트 핸들러와 스토어 액션의 분리

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[배움]
저도 같은 구조로 구현했는데 명확하게 정리하지 못하고 넘어갔던 부분을 정리해주셔서 이해가 편해졌습니다!

useEffect(() => {
fetchRestaurants();
}, [fetchRestaurants]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[질문]
RestaurantList는 목록을 보여주는 역할인데, 초기 fetch를 여기서 담당하면 데이터를 언제 불러올지 결정하는 책임도 함께 갖게 되지 않나요? App.jsx에서 호출하는 방식과 비교해서 이 위치를 선택하신 이유가 궁금합니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"데이터를 가져오는 것"과 "화면에 보여주는 것"을 같은 컴포넌트가 담당하는 것이 자연스럽다고 생각했습니다.
이 컴포넌트가 마운트될 때 데이터가 필요하다는 사실이 코드에서 바로 보여서 이 위치를 선택했습니다!

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.

2 participants