React Native Modalfy
v2.x
v2.x
  • Getting started
  • Installation
  • Guides
    • Creating a stack
    • Opening & closing
    • Passing params
    • Type checking with TypeScript
    • Subscribing to events
    • Using outside React
    • Upgrading from v1.x
  • API Reference
    • Types
      • ModalStackConfig
      • ModalOptions
      • ModalProp
      • ModalComponentProp
      • ModalComponentWithOptions
    • ModalProvider
    • createModalStack
    • useModal
    • withModal
    • modalfy
  • Blog
    • Announcing Modalfy v2
    • Stacks on stacks in React Native
    • Introducing a Modal Citizen
  • Others
    • Help
    • Contributing
    • Changelog
    • Github
Powered by GitBook
On this page

Was this helpful?

  1. API Reference

useModal

PreviouscreateModalStackNextwithModal

Last updated 4 years ago

Was this helpful?

Hooks that exposes Modalfy's API.

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

The object returned by useModal()is covered in .

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,
  }
}
import { ModalStackParamsList } from 'App'
// ...
const { openModal } = useModal<ModalStackParamsList>()

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

withModal()
ModalProp
your params types
https://github.com/colorfy-software/react-native-modalfy/blob/master/lib/useModal.ts