Skip to content

slorber/react-native-alert-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-alert-async

An Alert.alert() that you can await

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 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 or with Twitter.

About

An Alert.alert that you can await

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •