An open API service indexing awesome lists of open source software.

https://github.com/junkwarrior87/use-modal

Wrapper hooks for handling modal dialogs in React
https://github.com/junkwarrior87/use-modal

dialog hooks hooks-async modal modal-dialog react react-hooks

Last synced: about 2 months ago
JSON representation

Wrapper hooks for handling modal dialogs in React

Awesome Lists containing this project

README

        

# use-modal

Wrapper hooks for handling modal dialogs in React

## Install

```sh
npm i @goldfinger87/use-modal
```

## Usage

```tsx
import {Ref, useImperativeHandle} from 'react';
import {ModalHandle, useModal, useModalHandle} from '@goldfinger87/use-modal';

function Modal({handle}: { handle: Ref }) {
const [ref, imp] = useModal();
const {hide} = imp;
useImperativeHandle(handle, () => imp, []);
return
hide()}>hide
hide('returnValue')}>hide w/ value
;
}

function App() {
const modal = useModalHandle();
return <>

modal.current.show()}>show
modal.current.showAsync('init').then(console.log)}>showAsync
>;
}
```