1 import type { Dispatch, SetStateAction } from 'react';
3 import type { Modal, ModalManager } from './interface';
5 export default (modals: Modal[], setModals: Dispatch<SetStateAction<Modal[]>>): ModalManager => {
6 const hideModal = (id: string) => {
7 return setModals((oldModals: Modal[]) => {
8 return oldModals.map((old) => {
20 const removeModal = (id: string) => {
21 return setModals((oldModals) => {
22 return oldModals.filter(({ id: otherId }) => id !== otherId);
26 const createModal = (content: JSX.Element | undefined, id = Math.random().toString(36).slice(2, 11)) => {
27 setModals((oldModals) => {
28 return oldModals.find(({ id: otherId }) => id === otherId)
43 const getModal = (id: string) => {
44 return modals.find(({ id: otherId }) => id === otherId);