useModal
Same as withModal , useModal gives you access to the modal prop outside of a modal component. You'll use it if you want to take benefits or React's new hotness: hooks!
API reference
import React, { Component } from 'react'
import { Button, Text } from 'react-native'
import { useModal } from 'react-native-modalfy'
const ProfileScreen = () => {
const { openModal } = useModal()
return (
<View>
<Text>Welcome!</Text>
<Button
title="Edit"
onPress={() => openModal('EditProfile')}
/>
</View>
)
}
export default ProfileScreenUsing useModal will give you access to an object containing:
this.props.modalcurrentModal: name of the current displayed modal if there's oneopenModal: open a specific modalcloseModal: close a modalcloseModals: close every instance of a given modalcloseAllModals: close all opened modals
as seen in Modal prop.
Note: Hooks require React 16.8.0+ which means you'll need to be on React Native 0.59.0+ for useModal.
Last updated
Was this helpful?