React Native Modalfy
v3.x
v3.x
  • Getting started
  • Installation
  • 🤓Guides
    • Creating a stack
    • Opening & closing
    • Passing params
    • Triggering a callback
    • Type checking with TypeScript
    • Subscribing to events
    • Using outside React
    • Upgrading from v2.x
  • 📚API Reference
    • Types
      • ModalStackConfig
      • ModalOptions
      • ModalProp
      • ModalComponentProp
      • ModalProps
      • ModalComponentWithOptions
    • ModalProvider
    • createModalStack
    • useModal
    • withModal
    • modalfy
  • 📰Blog
    • Unveiling Modalfy v3
    • 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. Guides

Using outside React

PreviousSubscribing to eventsNextUpgrading from v2.x

Last updated 8 months ago

Was this helpful?

Thanks to the rewrite that led to Modalfy v2, we can now control our modals from outside React for the 1st time!

This means that we don't need to be inside any kind of component to open or close modals anymore. We could be in a function fetching some data or inside a Saga side effect and manage our modals without any problem.

To do so, simply we import { modalfy } from 'react-native-modalfy' in any file and we'll have access to the same as if we were using or :

import { modalfy } from 'react-native-modalfy'

const {
  currentModal,
  openModal,
  closeModal,
  closeModals,
  closeAllModals,
} = modalfy()

openModal('MessageSentModal')

To always get the latest value of currentModal, consider using modalfy().currentModal when you need that information, instead of the aforementioned destructuring syntax.

🤓
> modalfy() API
ModalProp
useModal()
withModal()