useModal

Hooks that exposes Modalfy's API.

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,
  }
}
https://github.com/colorfy-software/react-native-modalfy/blob/master/lib/useModal.ts

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

Was this helpful?