-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FE] refactor: 공용 모달 훅 추가 및 LongReviewItem 리팩토링 (#258)
* feat: 모달 상태 관리 훅 추가 * refactor: LongReviewItem 컴포넌트가 외부의 event를 props로 받을 수 있도록 변경
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 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
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,29 @@ | ||
import { useState } from 'react'; | ||
|
||
interface Modals { | ||
[key: string]: boolean; | ||
} | ||
|
||
const useModals = () => { | ||
const [modals, setModals] = useState<Modals>({}); | ||
|
||
const openModal = (key: string) => { | ||
setModals((prev) => ({ | ||
...prev, | ||
[key]: true, | ||
})); | ||
}; | ||
|
||
const closeModal = (key: string) => { | ||
setModals((prev) => ({ | ||
...prev, | ||
[key]: false, | ||
})); | ||
}; | ||
|
||
const isOpen = (key: string) => modals[key]; | ||
|
||
return { isOpen, openModal, closeModal }; | ||
}; | ||
|
||
export default useModals; |