Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/fsubal/react-async-dialog

await dialog.alert(<YourComponent />) out of the box
https://github.com/fsubal/react-async-dialog

Last synced: 16 days ago
JSON representation

await dialog.alert(<YourComponent />) out of the box

Awesome Lists containing this project

README

        

# react-async-dialog

Yes, you can do `await dialog.alert()` out of the box!

```
npm install react-async-dialog
```

```
yarn add react-async-dialog
```

![storybook.png](./README/storybook.png)

### Why?

[React](https://github.com/facebook/react) provides a first-class way to use [Portals](https://reactjs.org/docs/portals.html), which makes modals easy to create.

But sometimes, you want a modal window that interferes your event handlers.

```jsx
if (
await dialog.confirm(
<>
Are you REALLY sure?
>
)
) {
console.log("Ok, you are so sure!")
}
```

This library gives you this behavior out of the box!

### How to use

```jsx
import { DialogProvider, useDialog } from "react-async-dialog"

function YourApp({ save }) {
const dialog = useDialog()

const onSave = async e => {
e.preventDefault()

const ok = await dialog.confirm(Are you sure???, {
ok: "YES!!!"
})
if (!ok) {
return
}

save()
}

return SAVE ME
}

ReactDOM.render(


,
root
)
```

### Polyfills

`react-async-dialog` requires `Promise`.