-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#82) π¨ design: μ€νλμ μ μ μν λκΈ°νλ₯Ό μν Provider λ° μ»€μ€ν
ν
μ μ
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,31 @@ | ||
import React, { createContext, useState, useContext, ReactNode } from "react"; | ||
import { StadiumType } from "@/src/constants/ZoneData"; | ||
|
||
// 1. Context νμ μ μ | ||
interface StadiumContextType { | ||
selectedStadium: StadiumType | null; | ||
setSelectedStadium: (stadium: StadiumType) => void; | ||
} | ||
|
||
// 2. κΈ°λ³Έκ° μ€μ | ||
const StadiumContext = createContext<StadiumContextType | undefined>(undefined); | ||
|
||
// 3. Context Provider μ»΄ν¬λνΈ | ||
export const StadiumProvider: React.FC<{ children: ReactNode }> = ({ children }) => { | ||
const [selectedStadium, setSelectedStadium] = useState<StadiumType | null>(null); | ||
|
||
return ( | ||
<StadiumContext.Provider value={{ selectedStadium, setSelectedStadium }}> | ||
{children} | ||
</StadiumContext.Provider> | ||
); | ||
}; | ||
|
||
// 4. Context μ¬μ©μ μν 컀μ€ν ν | ||
export const useStadiumContext = (): StadiumContextType => { | ||
const context = useContext(StadiumContext); | ||
if (!context) { | ||
throw new Error("useStadiumContext must be used within a StadiumProvider"); | ||
} | ||
return context; | ||
}; |