1
- import { forwardRef , PropsWithChildren , useImperativeHandle , useState } from "react" ;
1
+ import { forwardRef , PropsWithChildren , useCallback , useImperativeHandle , useState } from "react" ;
2
2
import ReactDOM from "react-dom" ;
3
3
import { useHotkeys } from "react-hotkeys-hook" ;
4
4
import { availableHotkeys } from "../../../configs/hotkeysConfig" ;
@@ -40,23 +40,23 @@ export const Modal = forwardRef<ModalHandle, PropsWithChildren<ModalProps>>(({
40
40
const { t } = useTranslation ( ) ;
41
41
42
42
const [ isOpen , setOpen ] = useState ( open ) ;
43
+ const close = useCallback ( ( ) => {
44
+ if ( closeCallback !== undefined && ! closeCallback ( ) ) {
45
+ // Don't close modal
46
+ return ;
47
+ }
48
+ setOpen ( false ) ;
49
+ } , [ closeCallback ] ) ;
43
50
44
51
useImperativeHandle ( ref , ( ) => ( {
45
52
isOpen : ( ) => isOpen ,
46
53
open : ( ) => setOpen ( true ) ,
47
- close : ( ) => {
48
- if ( closeCallback !== undefined && ! closeCallback ( ) ) {
49
- // Don't close modal
50
- return ;
51
- }
52
- setOpen ( false ) ;
53
- } ,
54
- } ) , [ closeCallback , isOpen ] ) ;
54
+ close,
55
+ } ) , [ close , isOpen ] ) ;
55
56
56
57
useHotkeys (
57
58
availableHotkeys . general . CLOSE_MODAL . sequence ,
58
- //@ts -expect-error: TODO: Figure out what typescripts problem is
59
- ( ) => ref ?. current . close ?.( ) ,
59
+ close ,
60
60
{ description : t ( availableHotkeys . general . CLOSE_MODAL . description ) ?? undefined } ,
61
61
[ ref ] ,
62
62
) ;
@@ -72,8 +72,7 @@ export const Modal = forwardRef<ModalHandle, PropsWithChildren<ModalProps>>(({
72
72
< header >
73
73
< ButtonLikeAnchor
74
74
extraClassName = "fa fa-times close-modal"
75
- //@ts -expect-error: TODO: Figure out what typescripts problem is
76
- onClick = { ( ) => ref ?. current . close ?.( ) }
75
+ onClick = { close }
77
76
tabIndex = { 0 }
78
77
/>
79
78
< h2 >
0 commit comments