为什么按钮的 onPress 中的警报会使 expo 应用程序崩溃?
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'
/>
谁能帮我解释一下这是为什么?
谢谢!
编辑:
我是 运行 Android 6.0,使用 Expo 客户端版本 1.18.4
的 LG G3
从 react-native
导入警报
import {
Alert,
} from 'react-native';
然后像下面这样调用它:
function testfn(theString){
Alert.alert(theString);
}
或
<Button
onPress = {() => Alert.alert(this.state.text)}
title = 'Send'
color = '#1DA237'
/>
此代码有效。
<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' />
谁能帮我解释一下这是为什么?
谢谢!
编辑:
我是 运行 Android 6.0,使用 Expo 客户端版本 1.18.4
从 react-native
import {
Alert,
} from 'react-native';
然后像下面这样调用它:
function testfn(theString){
Alert.alert(theString);
}
或
<Button
onPress = {() => Alert.alert(this.state.text)}
title = 'Send'
color = '#1DA237'
/>