Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/slorber/react-native-alert-async
An Alert.alert that you can await
https://github.com/slorber/react-native-alert-async
Last synced: about 1 month ago
JSON representation
An Alert.alert that you can await
- Host: GitHub
- URL: https://github.com/slorber/react-native-alert-async
- Owner: slorber
- License: mit
- Created: 2018-11-19T17:16:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-03T15:19:58.000Z (almost 5 years ago)
- Last Synced: 2024-10-03T12:19:30.778Z (2 months ago)
- Language: JavaScript
- Homepage: https://sebastienlorber.com
- Size: 7.81 KB
- Stars: 47
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - react-native-alert-async - An Alert.alert that you can await (JavaScript)
README
# react-native-alert-async
An Alert.alert() that you can await
```jsx
import AlertAsync from "react-native-alert-async";const myAction = async () => {
const choice = await AlertAsync(
'Title',
'Message',
[
{text: 'Yes', onPress: () => 'yes'},
{text: 'No', onPress: () => Promise.resolve('no')},
],
{
cancelable: true,
onDismiss: () => 'no',
},
);if (choice === 'yes') {
await doSomething();
}
else {
await doSomethingElse();
}
}
```It always returns a promise, and that promise is guaranteed to resolve after the user made his choice.
It's just a wrapper around the original RN API so it's very tiny and does not require native code/linking, and is compatible with Expo.
There is an existing [RN PR](https://github.com/facebook/react-native/pull/20312) waiting to be merged with this feature. In the meantime you can use this package.
I use this in production for a long time and it's reliable.# Hire a freelance expert
Looking for a React/ReactNative freelance expert with more than 5 years production experience?
Contact me from my [website](https://sebastienlorber.com/) or with [Twitter](https://twitter.com/sebastienlorber).