-
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: Modal Context 게임 시작 부분 적용 #272
- Loading branch information
Showing
3 changed files
with
14 additions
and
29 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
17 changes: 1 addition & 16 deletions
17
frontend/src/components/StartButtonContainer/StartButtonContainer.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 |
---|---|---|
@@ -1,22 +1,7 @@ | ||
import StartButton from './StartButton/StartButton'; | ||
import AlertModal from '../common/AlertModal/AlertModal'; | ||
|
||
import useModal from '@/hooks/useModal'; | ||
|
||
const StartButtonContainer = () => { | ||
const { isOpen, show, close } = useModal(); | ||
|
||
return ( | ||
<> | ||
<StartButton show={show} /> | ||
<AlertModal | ||
isOpen={isOpen} | ||
onClose={close} | ||
title="게임 시작 에러" | ||
message="게임을 시작할 수 없습니다." | ||
/> | ||
</> | ||
); | ||
return <StartButton />; | ||
}; | ||
|
||
export default StartButtonContainer; |
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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import { useState } from 'react'; | ||
import { useContext } from 'react'; | ||
|
||
const useModal = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const show = () => { | ||
setIsOpen(true); | ||
}; | ||
import { ModalDispatchContext } from '@/providers/ModalProvider/ModalProvider'; | ||
|
||
const close = () => { | ||
setIsOpen(false); | ||
}; | ||
const useModal = () => { | ||
const dispatch = useContext(ModalDispatchContext); | ||
|
||
return { isOpen, show, close }; | ||
if (dispatch === null) { | ||
throw new Error('ModalDispatchContext가 존재하지 않습니다.'); | ||
} | ||
return dispatch; | ||
}; | ||
export default useModal; |