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
  1. 🤓Guides

Using outside React

PreviousSubscribing to eventsNextUpgrading from v2.x

Last updated 1 year ago

Was this helpful?

CtrlK

Was this helpful?

> modalfy() API

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 ModalProp as if we were using useModal() or withModal():

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

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

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

openModal('MessageSentModal')