Skip to content

Commit

Permalink
feat: #43 - useModalLogic 훅에 useCallback 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dudwns committed Nov 4, 2023
1 parent 920a0de commit 5d3e665
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/components/common/Modal/hooks/useModalLogic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react'
import { useCallback, useEffect } from 'react'

export interface useModalLogicProps {
onClose: (e?: React.MouseEvent<HTMLButtonElement>) => void
Expand Down Expand Up @@ -29,16 +29,22 @@ const useModalLogic = ({
}
}, [onClose, onConfirm])

const handleClickOverlay = (e: React.MouseEvent<HTMLDivElement>) => {
if (e.target === modalRef.current) {
onClose()
}
}
const handleClickOverlay = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
if (e.target === modalRef.current) {
onClose()
}
},
[modalRef, onClose],
)

const handleClickConfirm = (e?: React.MouseEvent<HTMLButtonElement>) => {
onConfirm?.()
onClose()
}
const handleClickConfirm = useCallback(
(e?: React.MouseEvent<HTMLButtonElement>) => {
onConfirm?.()
onClose()
},
[onConfirm, onClose],
)

return { handleClickOverlay, handleClickConfirm }
}
Expand Down

0 comments on commit 5d3e665

Please sign in to comment.