簡體   English   中英

為什么onPress中的Button警報會導致博覽會應用程序崩潰?

[英]Why does an alert in onPress of a Button crash the expo app?

此代碼有效。

<Button
  onPress = {() => testfn(this.state.text)}
  title = 'Send'
  color = '#1DA237'
/>

function testfn(theString) {
  alert(theString);
}

但是,此代碼使expo應用程序在構建時崩潰。

 <Button onPress = {() => alert(this.state.text)} title = 'Send' color = '#1DA237' /> 

誰能為我澄清為什么?

謝謝!

編輯:
我在裝有Expo Client版本1.18.4的LG G3上運行Android 6.0

react-native導入警報

import {
  Alert,
} from 'react-native';

然后像下面這樣調用它:

function testfn(theString){
   Alert.alert(theString);
}

要么

<Button
  onPress = {() => Alert.alert(this.state.text)}
  title = 'Send'
  color = '#1DA237'
/>

參考: https : //facebook.github.io/react-native/docs/alert.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM