Skip to content

Commit 8e1af7b

Browse files
authored
Bugfix: fix dialogOptions.customkey not being respected (#112)
Co-authored-by: Alex Nicholson <alex.n@clove.kitchen>
1 parent 14b0de2 commit 8e1af7b

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/react-dialog-async/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-dialog-async",
33
"description": "A promise-based way to show dialogs in React",
44
"type": "module",
5-
"version": "2.3.0",
5+
"version": "2.3.1",
66
"sideEffects": false,
77
"main": "index.js",
88
"module": "index.esm.js",

packages/react-dialog-async/src/useDialog.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { useCallback, useContext, useEffect, useId, useMemo } from 'react';
22
import DialogContext from './DialogContext';
3-
import { hashComponent } from './utils';
43
import { DialogComponent, useDialogOptions, useDialogReturn } from './types';
4+
import { hashComponent } from './utils';
55

66
function 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

Comments
 (0)