-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodal-provider.tsx
More file actions
45 lines (38 loc) Β· 990 Bytes
/
modal-provider.tsx
File metadata and controls
45 lines (38 loc) Β· 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { useEffect, useState, type ReactNode } from "react";
import { useLocation } from "react-router-dom";
import { modalStore } from "@/shared/model/store";
import { Modal } from "../../shared/ui/modal/modal";
interface ModalItem {
id: string;
content: ReactNode;
autoPlay?: number;
size?: "default" | "auto";
}
export const ModalProvider = () => {
const location = useLocation();
const [modals, setModals] = useState<ModalItem[]>([]);
useEffect(() => {
const unsubscribe = modalStore.subscribe(setModals);
return unsubscribe;
}, []);
useEffect(() => {
modalStore.reset();
}, [location.key]);
return (
<>
{modals.map((modal) => {
return (
<Modal
key={modal.id}
isOpen={true}
autoPlay={modal.autoPlay}
onClose={() => modalStore.close(modal.id)}
size={modal.size}
>
{modal.content}
</Modal>
);
})}
</>
);
};