useDisclose handles common open, close, or toggle scenarios and can control feedback components such as Modal, AlertDialog, Drawer, etc.
import { useDisclose } from 'native-base';
const Example = () => {
const {
isOpen,
onOpen,
onClose
} = useDisclose();
return <Center>
<Modal isOpen={isOpen} onClose={onClose}>
<Modal.Content>
<Modal.CloseButton />
<Modal.Header fontSize="4xl" fontWeight="bold">
Delete Customer
</Modal.Header>
<Modal.Body>
This will remove all data relating to Alex. This action cannot be
reversed. Deleted data can not be recovered.
</Modal.Body>
<Modal.Footer>
<Button variant="unstyled" mr="1" onPress={onClose}>
Cancel
</Button>
<Button colorScheme="error" onPress={onClose}>
Delete
</Button>
</Modal.Footer>
</Modal.Content>
</Modal>
<Button onPress={onOpen}>Open Modal</Button>
</Center>;
};
The useDisclosure hook returns an object with the following fields:
isOpen: ( boolean ) Show the component; triggers the enter or exit states.
onClose: ( function ) Callback function to set a falsy value for the isOpen parameter.
onOpen: ( function ) Callback function to set a truthy value for the isOpen parameter.
onToggle: ( function ) Callback function to toggle the value of the isOpen parameter.