Skip to content

Commit

Permalink
✨ Add new hook for modal state
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Jun 1, 2023
1 parent 8890668 commit 9c7ffe4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions client/src/app/shared/hooks/useCreateEditModalState.ts
@@ -0,0 +1,18 @@
import React from "react";

type ModalState<T> =
| { mode: "create"; resource: null }
| { mode: "create"; resource: T }
| { mode: "edit"; resource: T }
| null;

export default function useCreateEditModalState<T>() {
const [modalState, setModalState] = React.useState<ModalState<T>>(null);
const isModalOpen = modalState !== null;

return {
modalState,
setModalState,
isModalOpen,
};
}

0 comments on commit 9c7ffe4

Please sign in to comment.