> For the complete documentation index, see [llms.txt](https://colorfy-software.gitbook.io/react-native-modalfy/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://colorfy-software.gitbook.io/react-native-modalfy/guides/outside-react.md).

# Using outside React

#### [**> modalfy() API**](/react-native-modalfy/api/modalfy.md)

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.&#x20;

To do so, simply we `import { modalfy } from 'react-native-modalfy'` in any file and we'll have access to the same [**`ModalProp`**](/react-native-modalfy/api/types/modalprop.md) as if we were using [**`useModal()`**](/react-native-modalfy/api/usemodal.md) or [**`withModal()`**](/react-native-modalfy/api/withmodal.md):

{% tabs %}
{% tab title="JavaScript" %}

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

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

openModal('MessageSentModal')
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
To always get the latest value of `currentModal,` consider using `modalfy().currentModal` when you need that information, instead of the aforementioned destructuring syntax.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://colorfy-software.gitbook.io/react-native-modalfy/guides/outside-react.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
