Skip to content

Commit 346a2e6

Browse files
committed
feature : 상태관리 zustand 방식으로 변경
1 parent 846be4d commit 346a2e6

File tree

6 files changed

+65
-17
lines changed

6 files changed

+65
-17
lines changed

package-lock.json

Lines changed: 34 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"react-chartjs-2": "^5.2.0",
1919
"react-dom": "^18.3.1",
2020
"react-lottie-player": "^2.1.0",
21-
"react-router-dom": "^6.27.0"
21+
"react-router-dom": "^6.27.0",
22+
"zustand": "^5.0.1"
2223
},
2324
"devDependencies": {
2425
"@eslint/js": "^9.11.1",

src/App.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ function App() {
1111
const [queryClient] = useState(() => new QueryClient());
1212
return (
1313
<QueryClientProvider client={queryClient}>
14-
<UsePlayingProvider>
15-
<ChartProvider>
16-
<BrowserRouter>
17-
<SpeedInsights />
18-
<Routes>
19-
<Route path="/" element={<Home />} />
20-
</Routes>
21-
</BrowserRouter>
22-
</ChartProvider>
23-
</UsePlayingProvider>
14+
{/* <UsePlayingProvider> */}
15+
<ChartProvider>
16+
<BrowserRouter>
17+
<SpeedInsights />
18+
<Routes>
19+
<Route path="/" element={<Home />} />
20+
</Routes>
21+
</BrowserRouter>
22+
</ChartProvider>
23+
{/* </UsePlayingProvider> */}
2424
</QueryClientProvider>
2525
);
2626
}

src/common/Loading.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { useEffect, useState } from "react";
22
import Lottie from "react-lottie-player";
33
import LoadingLottie from "../assets/lottie/loading.json";
44
import { usePlaying } from "../hook/usePlayingContext";
5+
import usePlayingStore from "../store/playing";
56

67
export default function Loading() {
78
const [mounted, setMounted] = useState(false);
8-
const { isPlaying, toggleIsPlaying } = usePlaying();
9+
// const { isPlaying, toggleIsPlaying } = usePlaying();
10+
const { isPlaying, toggleIsPlaying } = usePlayingStore();
911

1012
useEffect(() => setMounted(true), []);
1113

src/hook/useDynamicData.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { useEffect, useRef, useState } from "react";
33
import { usePlaying } from "./usePlayingContext";
4+
import usePlayingStore from "../store/playing";
45

56
const useDynamicData = (
67
initialData: any,
@@ -10,7 +11,8 @@ const useDynamicData = (
1011
const containerRef = useRef<HTMLDivElement>(null);
1112
const [isVisible, setIsVisible] = useState(false);
1213
const [firstLoad, setFirstLoad] = useState(true);
13-
const { isPlaying } = usePlaying();
14+
// const { isPlaying } = usePlaying();
15+
const { isPlaying } = usePlayingStore();
1416

1517
const { data: data, refetch } = useQuery({
1618
queryKey: [queryKey],

src/store/playing.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { create } from "zustand";
2+
3+
interface PlayingState {
4+
isPlaying: boolean;
5+
toggleIsPlaying: () => void;
6+
}
7+
8+
const usePlayingStore = create<PlayingState>((set) => ({
9+
isPlaying: true,
10+
toggleIsPlaying: () => set((state) => ({ isPlaying: !state.isPlaying })),
11+
}));
12+
13+
export default usePlayingStore;

0 commit comments

Comments
 (0)