diff options
author | Minseo Lee <itoupluk427@gmail.com> | 2024-03-06 19:38:48 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-06 19:38:48 +0900 |
commit | f3db23a3b14e9444cb499c727b9d62c414e5a840 (patch) | |
tree | 4b9f39447c7c53d2baf3dd4029b2f8ea30e3c9b1 /src/components/Dialog/context.ts | |
parent | 0c6a82062f9c9c47338fe50f0ef37a1c068939c2 (diff) | |
parent | eb298d2e60a0ddf26ebaf8f27373418bbf7769e3 (diff) | |
download | voidsky-f3db23a3b14e9444cb499c727b9d62c414e5a840.tar.zst |
Merge branch 'bluesky-social:main' into patch-3
Diffstat (limited to 'src/components/Dialog/context.ts')
-rw-r--r-- | src/components/Dialog/context.ts | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/components/Dialog/context.ts b/src/components/Dialog/context.ts index eb717d8e2..9b571e8e9 100644 --- a/src/components/Dialog/context.ts +++ b/src/components/Dialog/context.ts @@ -21,7 +21,8 @@ export function useDialogControl(): DialogOuterProps['control'] { open: () => {}, close: () => {}, }) - const {activeDialogs} = useDialogStateContext() + const {activeDialogs, openDialogs} = useDialogStateContext() + const isOpen = openDialogs.includes(id) React.useEffect(() => { activeDialogs.current.set(id, control) @@ -31,14 +32,18 @@ export function useDialogControl(): DialogOuterProps['control'] { } }, [id, activeDialogs]) - return { - id, - ref: control, - open: () => { - control.current.open() - }, - close: cb => { - control.current.close(cb) - }, - } + return React.useMemo<DialogOuterProps['control']>( + () => ({ + id, + ref: control, + isOpen, + open: () => { + control.current.open() + }, + close: cb => { + control.current.close(cb) + }, + }), + [id, control, isOpen], + ) } |