Hooks that exposes Modalfy's API.

Note: Prefer withModal() HOC if you're using a Class component.

The object returned by useModal()is covered in ModalProp.

const useModal = <P extends ModalfyParams>(): UsableModalProp<P> => {
  const context: UsableModalProp<P> = React.useContext(ModalContext)
  return {
    closeAllModals: context.closeAllModals,

    closeModal: context.closeModal,

    closeModals: context.closeModals,

    currentModal: context.currentModal,

    openModal: context.openModal,

If you're using TypeScript and have your params types, you can get some nice autocomplete by utilising useModal()like this:

import { ModalStackParamsList } from 'App'
// ...
const { openModal } = useModal<ModalStackParamsList>()

Last updated