アプリを作る時、アラートを出したい時があると思います。
以下のようなアラートを出す方法です。(ios, android対応)
バージョン
- react-native -> 0.61.5

0.61では特にライブラリをインストールする必要はないようです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import {Alert} from 'react-native'; | |
Alert.alert( | |
'エラー', | |
'回答が選択されていません。', | |
[ | |
{ | |
text: 'Ask me later', | |
onPress: () => { | |
console.log('Ask me later pressed'); | |
}, | |
}, | |
{ | |
text: 'Cancel', | |
onPress: () => { | |
console.log('Cancel Pressed'); | |
}, | |
style: 'cancel', | |
}, | |
{ | |
text: 'OK', | |
onPress: () => { | |
console.log('OK Pressed'); | |
}, | |
} | |
], | |
{cancelable: false}, | |
); |