-
Notifications
You must be signed in to change notification settings - Fork 0
[Step2.2] cactus: Zustand 적용하기 #6
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
ehlung
wants to merge
10
commits into
cactus-adv-2.1
Choose a base branch
from
cactus-adv-2.2
base: cactus-adv-2.1
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.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
470a828
chore: zustand 설치
ehlung 552f3bf
feat: RestaurantStore, FilterStore 생성
ehlung a8cd2b8
refactor: Context API → Zustand 마이그레이션
ehlung 08d7e25
refactor: 에러 초기화 및 localStorage 키 이름 개선
ehlung 01f7fa4
docs: README 1차 반영
ehlung fbb22c5
refactor: localStorage → sessionStorage 전환
ehlung dbd9b29
refactor: useRestaurantData 커스텀 훅 추출
ehlung 787d67b
docs: adv-2.2 README 작성 완료
ehlung e4fbe03
refactor: useRestaurantData 훅 제거하고 컴포넌트에서 직접 구독
ehlung 3980143
docs: README 리팩토링 및 내용 반영
ehlung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,9 @@ | ||
| import React from "react"; | ||
| import ReactDOM from "react-dom/client"; | ||
| import App from "./App.jsx"; | ||
| import { RestaurantProvider } from "./context/RestaurantContext"; | ||
|
|
||
| ReactDOM.createRoot(document.getElementById("root")).render( | ||
| <React.StrictMode> | ||
| <RestaurantProvider> | ||
| <App /> | ||
| </RestaurantProvider> | ||
| </React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| ); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { create } from "zustand"; | ||
| import { persist, createJSONStorage } from "zustand/middleware"; | ||
| import { ALL_CATEGORY } from "../constants/categories"; | ||
|
|
||
| const useFilterStore = create( | ||
| persist( | ||
| (set) => ({ | ||
| selectedCategory: ALL_CATEGORY, | ||
| setSelectedCategory: (category) => set({ selectedCategory: category }), | ||
| }), | ||
| { | ||
| name: "self-paced-react-category", | ||
| storage: createJSONStorage(() => sessionStorage), | ||
| }, | ||
| ), | ||
| ); | ||
|
|
||
| export default useFilterStore; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { create } from "zustand"; | ||
| import { getRestaurants, addRestaurant } from "../api"; | ||
|
|
||
| const useRestaurantStore = create((set, get) => ({ | ||
| newRestaurants: [], | ||
| error: null, | ||
| isLoading: false, | ||
|
|
||
| fetchRestaurants: async () => { | ||
| set({ isLoading: true, error: null }); | ||
| try { | ||
| const data = await getRestaurants(); | ||
| set({ newRestaurants: data }); | ||
| } catch { | ||
| set({ error: "음식점 목록을 불러오지 못했습니다." }); | ||
| } finally { | ||
| set({ isLoading: false }); | ||
| } | ||
| }, | ||
|
|
||
| registerRestaurant: async (newRestaurant) => { | ||
| await addRestaurant(newRestaurant); | ||
| await get().fetchRestaurants(); | ||
| }, | ||
| })); | ||
|
|
||
| export default useRestaurantStore; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[배움]
저는 localStorage를 사용했는데 카테고리 필터의 경우에는 지금 내가 보고 있는 화면의 상태로 다음에 앱을 열면 전체 목록부터 다시 보는 것이 자연스러운 탐색 상태라고 생각되네요! 이 점에서 sessionStorage가 더 적절한 것 같습니다.