首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当我使用Alert.alert()时,expo关闭

当我使用Alert.alert()时,expo关闭
EN

Stack Overflow用户
提问于 2020-03-01 23:47:28
回答 1查看 1K关注 0票数 0

描述

我有一个提交按钮,我使用这个函数来处理响应。当我使用Alert.alert()接口时,它会在没有任何警告的情况下自动关闭expo。

预期行为

我预计会在模拟器上看到弹出的警告,您执行了什么操作,您希望发生什么?

观察到的行为

世博会立即在电话或模拟器上关闭

环境

Expo CLI 3.13.1环境信息:系统: OS: macOS 10.15.3外壳: 5.7.1 - /bin/zsh二进制文件: Node: 12.14.0 - /usr/local/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.13.7 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman IDEs: Android Studio: 3.5AI-191.8026.42.35.6010548 Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild npmPackages: expo:^36.0.0 => 36.0.2 react: 16.9.0 => 16.9.0 react-native:https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz => 0.61.4 npmGlobalPackages: expo-cli: 3.13.1

Iphone11模拟器和expo物理版Iphone x

可重现的演示

代码语言:javascript
运行
复制
import {Alert, Button, } from 'react-native';
const submitButton =  () => {
    Alert.alert('error', [{ text: 'Ok' }]);
 }

//inside return func
<Button title="Submit" onPress={submitButton} />
EN

回答 1

Stack Overflow用户

发布于 2020-03-02 12:55:41

它崩溃了,因为你没有传递‘消息’。无论消息是否为空,都必须写入消息。

代码语言:javascript
运行
复制
    syntax of Alert :- static alert(title, message?, buttons?, options? type?)

    yes. we knew that message Parameter is optional , but still you have to pass it when you use Alert.alert(), might be it is expo error . 

1)解决方案

代码语言:javascript
运行
复制
const submitButton =  () => {
    Alert.alert('error','', [{ text: 'Ok' }]);
 }

2)解决方案

代码语言:javascript
运行
复制
const submitButon = () => {
    alert('error', [{ text: 'Ok' }]);
}

It will solved your problem 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60476833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档