11import { useCallback , useContext , useEffect , useId , useMemo } from 'react' ;
22import DialogContext from './DialogContext' ;
3- import { hashComponent } from './utils' ;
43import { DialogComponent , useDialogOptions , useDialogReturn } from './types' ;
4+ import { hashComponent } from './utils' ;
55
66function useDialog < D , R , DE extends D | undefined > (
77 component : DialogComponent < D , R > ,
88 options ?: useDialogOptions < D , DE > ,
99) : useDialogReturn < D , R , DE > {
10- const id = useId ( ) ;
10+ const internalId = useId ( ) ;
1111
12- const key = useMemo (
13- ( ) => options ?. customKey ?? hashComponent ( component ) ,
14- [ component , options ?. customKey ] ,
15- ) ;
12+ const id = useMemo ( ( ) => {
13+ if ( options ?. customKey !== undefined ) {
14+ return `${ hashComponent ( component ) } -${ options . customKey } ` ;
15+ }
16+
17+ return internalId ;
18+ } , [ internalId , component , options ?. customKey ] ) ;
1619
1720 const ctx = useContext ( DialogContext ) ;
1821
@@ -39,7 +42,7 @@ function useDialog<D, R, DE extends D | undefined>(
3942 options ?. unmountDelayInMs ,
4043 ) ;
4144 } ,
42- [ key , component , options ?. defaultData , options ?. unmountDelayInMs ] ,
45+ [ id , component , options ?. defaultData , options ?. unmountDelayInMs ] ,
4346 ) ;
4447
4548 const hide = ( ) => {
0 commit comments