# withModal

`withModal` is a HOC ([Higher Order Component](https://reactjs.org/docs/higher-order-components.html)) which passes the `modal` prop into a wrapped component. The function receives a component and outputs another one with the new prop. It's useful when you don't have access to the `modal` prop into the component, or don't want to pass it in case of a deeply nested child.

## API reference

```javascript
import React, { Component } from 'react'
import { Button, Text } from 'react-native'
import { withModal } from 'react-native-modalfy'

class ProfileScreen extends Component {
  render() {
    return (
      <View>
        <Text>Welcome!</Text>
        <Button
          title="Edit"
          onPress={() => this.props.modal.openModal('EditProfile')}
        />
      </View>
    )
  }
}

export default withModal(ProfileScreen)
```

Using `withModal` will give you access to:

* `this.props.modal`
  * `currentModal`: name of the current displayed modal if there's one
  * `openModal`: open a specific modal
  * `closeModal`: close a modal
  * `closeModals`: close every instance of a given modal
  * `closeAllModals`: close all opened modals

as seen in [Modal prop](https://colorfy-software.gitbook.io/react-native-modalfy/1.x/modal-prop#api-reference).


---

# Agent Instructions: 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:

```
GET https://colorfy-software.gitbook.io/react-native-modalfy/1.x/api/with-modal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
