@uniai-fe/uds-templates 0.3.12 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useCallback } from "react";
|
|
3
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
4
4
|
|
|
5
5
|
import { useAtom } from "jotai";
|
|
6
6
|
|
|
@@ -28,6 +28,12 @@ const ensureDelay = (value?: number): number =>
|
|
|
28
28
|
*/
|
|
29
29
|
export function useModal(): UseModalReturn {
|
|
30
30
|
const [modalStacks, updateModalStack] = useAtom(modalStackAtom);
|
|
31
|
+
const modalStacksRef = useRef(modalStacks);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
// 변경 설명: closeModal이 최신 stack 상태를 기준으로 대상을 찾도록 현재 스냅샷 ref를 동기화한다.
|
|
35
|
+
modalStacksRef.current = modalStacks;
|
|
36
|
+
}, [modalStacks]);
|
|
31
37
|
|
|
32
38
|
const newModal = useCallback(
|
|
33
39
|
<FormContext extends FieldValues>(newStack: ModalState<FormContext>) => {
|
|
@@ -87,7 +93,7 @@ export function useModal(): UseModalReturn {
|
|
|
87
93
|
|
|
88
94
|
const closeModal = useCallback(
|
|
89
95
|
({ stackKey, callback }: ModalCloseRequest) => {
|
|
90
|
-
const targetStack =
|
|
96
|
+
const targetStack = modalStacksRef.current.find(
|
|
91
97
|
stack => stack.stackKey === stackKey,
|
|
92
98
|
);
|
|
93
99
|
|
|
@@ -121,7 +127,7 @@ export function useModal(): UseModalReturn {
|
|
|
121
127
|
callback?.();
|
|
122
128
|
}, resolvedDelay);
|
|
123
129
|
},
|
|
124
|
-
[
|
|
130
|
+
[updateModalStack],
|
|
125
131
|
);
|
|
126
132
|
|
|
127
133
|
return { modalStacks, newModal, updateModal, closeModal };
|