Skip to content

Commit 045c17d

Browse files
committed
Update API
1 parent 4e4642c commit 045c17d

3 files changed

Lines changed: 10 additions & 41 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ export type useDialogOptions<D, DE extends D | undefined> = {
1010
unmountDelayInMs?: number;
1111
/**
1212
* By default, the dialog will be hidden if the hook is unmounted. Set this to
13-
* false if you want the dialog to remain open even when the hook is unmounted.
14-
* @default true
13+
* true if you want the dialog to persist even when the hook is unmounted.
1514
*/
16-
hideOnHookUnmount?: boolean;
15+
persistOnUnmount?: boolean;
1716
};
1817

1918
export type useDialogReturn<D, R, DE extends D | undefined> = {

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
useCallback,
3-
useContext,
4-
useEffect,
5-
useId,
6-
useMemo,
7-
useRef,
8-
} from 'react';
1+
import { useCallback, useContext, useEffect, useId, useRef } from 'react';
92
import type { AsyncDialogComponent } from '../types.js';
103
import type { useDialogOptions, useDialogReturn } from './types.js';
114
import { DialogActionsContext } from '../context/DialogActionsContext.js';
@@ -18,15 +11,7 @@ export function useDialog<D, R, DE extends D | undefined>(
1811
options?: useDialogOptions<D, DE>,
1912
): useDialogReturn<D, R, DE> {
2013
const idCount = useRef(0);
21-
const internalId = useId();
22-
23-
const id = useMemo(() => {
24-
if (options?.customKey !== undefined) {
25-
return options.customKey;
26-
}
27-
28-
return internalId;
29-
}, [internalId, component, options?.customKey]);
14+
const id = useId();
3015

3116
const ctx = useContext(DialogActionsContext);
3217

@@ -38,11 +23,11 @@ export function useDialog<D, R, DE extends D | undefined>(
3823

3924
useEffect(() => {
4025
return () => {
41-
if (options?.hideOnHookUnmount !== false) {
26+
if (options?.persistOnUnmount !== true) {
4227
ctx.hide(id);
4328
}
4429
};
45-
}, [id, options?.hideOnHookUnmount]);
30+
}, [id, options?.persistOnUnmount]);
4631

4732
const open = useCallback(
4833
async (data?: D): Promise<R | undefined> => {

packages/react-dialog-async/src/useDialogLazy/useDialogLazy.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
useCallback,
3-
useContext,
4-
useEffect,
5-
useId,
6-
useMemo,
7-
useRef,
8-
} from 'react';
1+
import { useCallback, useContext, useEffect, useId, useRef } from 'react';
92
import type { useDialogLazyReturn } from './types.js';
103
import type { AsyncDialogComponent } from '../types.js';
114
import type { useDialogOptions } from '../useDialog/types.js';
@@ -15,18 +8,10 @@ export function useDialogLazy<D, R, DE extends D | undefined>(
158
componentLoader: () => Promise<AsyncDialogComponent<D, R>>,
169
options?: useDialogOptions<D, DE>,
1710
): useDialogLazyReturn<D, R, DE> {
18-
const internalId = useId();
11+
const id = useId();
1912
let idCount = useRef(0);
2013
const componentRef = useRef<AsyncDialogComponent<D, R> | null>(null);
2114

22-
const id = useMemo(() => {
23-
if (options?.customKey !== undefined) {
24-
return options.customKey;
25-
}
26-
27-
return internalId;
28-
}, [internalId, options?.customKey]);
29-
3015
const ctx = useContext(DialogActionsContext);
3116

3217
if (!ctx) {
@@ -48,11 +33,11 @@ export function useDialogLazy<D, R, DE extends D | undefined>(
4833

4934
useEffect(() => {
5035
return () => {
51-
if (options?.hideOnHookUnmount !== false) {
36+
if (options?.persistOnUnmount !== true) {
5237
ctx.hide(id);
5338
}
5439
};
55-
}, [id, options?.hideOnHookUnmount]);
40+
}, [id, options?.persistOnUnmount]);
5641

5742
const open = useCallback(
5843
async (data?: D): Promise<R | undefined> => {

0 commit comments

Comments
 (0)