-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 전역 상태에서 context provider 기반으로 리팩토링
- Loading branch information
Showing
7 changed files
with
74 additions
and
29 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
src/app/(playground)/playground/map/_components/AddressSearchButton/index.tsx
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
44 changes: 44 additions & 0 deletions
44
src/app/(playground)/playground/map/_components/KakaoAddressContext/index.tsx
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,44 @@ | ||
"use client"; | ||
|
||
import { createContext, ReactNode, useContext, useState } from "react"; | ||
|
||
export interface Coordinate { | ||
latitude: number; | ||
longitude: number; | ||
} | ||
|
||
interface KakaoAddressContextType { | ||
coordinate: Coordinate; | ||
setCoordinate: (latitude: number, longitude: number) => void; | ||
} | ||
|
||
const KakaoAddressContext = createContext<KakaoAddressContextType | undefined>( | ||
undefined, | ||
); | ||
|
||
export function KakaoAddressProvider({ children }: { children: ReactNode }) { | ||
const [coordinate, setCoordinateState] = useState<Coordinate>({ | ||
latitude: 37.566828, | ||
longitude: 126.9786567, | ||
}); | ||
|
||
const setCoordinate = (latitude: number, longitude: number) => { | ||
setCoordinateState({ latitude, longitude }); | ||
}; | ||
|
||
return ( | ||
<KakaoAddressContext.Provider value={{ coordinate, setCoordinate }}> | ||
{children} | ||
</KakaoAddressContext.Provider> | ||
); | ||
} | ||
|
||
export function useKakaoAddress() { | ||
const context = useContext(KakaoAddressContext); | ||
if (context === undefined) { | ||
throw new Error( | ||
"useKakaoAddress must be used within a KakaoAddressProvider", | ||
); | ||
} | ||
return context; | ||
} |
2 changes: 1 addition & 1 deletion
2
src/app/(playground)/playground/map/_components/KakaoMap/index.tsx
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
1 change: 1 addition & 0 deletions
1
src/app/(playground)/playground/map/_components/MapUtilsButton/UtilsContainer/index.tsx
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 @@ | ||
export default function UtilsContainer() {} |
Empty file.
24 changes: 0 additions & 24 deletions
24
src/app/(playground)/playground/map/_store/KakaoAdressStore.ts
This file was deleted.
Oops, something went wrong.
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