RootUI
useModal

useModal

Hook to reuse modals with ease.

useModal<T>(
  ModalComponent: FC<T>,
  opts?: ModalOpts
): (props?: T) => Promise<any>

Example

useModal is a hook abstraction around the modalService.open method. It provides a simple way to open modals, while also closing the modal when your component unmounts.

function MyComponent() {
  const helloWorldModal = useModal(() => <div>Hello, World!</div>);
  return <button onClick={helloWorldModal}>Open Modal</button>;
}

Pass in a component to render:

function MyComponent() {
  const helloWorldModal = useModal(() => <div>Hello, World!</div>);
  return <button onClick={helloWorldModal}>Open Modal</button>;
}

ModalOpts