undefined 不是一个对象(评估 '_this2.props.navigation.navigate') Alert.alert [英] undefined is not an object(evaluating '_this2.props.navigation.navigate') Alert.alert

查看:37
本文介绍了undefined 不是一个对象(评估 '_this2.props.navigation.navigate') Alert.alert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要发出警报,当按下警报时,我需要转到其他屏幕,但是,expo 向我显示该错误,这是我的代码

I need to do an alert, when the alert is pressed, i need to go to other screen, but, expo show me that error, this is my code

    AlertaDi(){

      Alert.alert(
      'Alert Title',
      'Correcto',
      [
        {text: '==>', onPress: () => 
        this.props.navigation.navigate('InicioBot')}
      ],
    );

  }

如果我使用

onPress={() => this.props.navigation.navigate('InicioBot')} 

在按钮中,它可以工作,但我需要在事件中进行导航

in a button, it works, but i need that navigation in an event

推荐答案

我找到了另一个解决方案,在 onPress 按钮你可以放

I found another solution, in onPress of the button you may to put

onPress={() => this.AlertaDi(this.props.navigation)}

喜欢这个

<View style={{width:'15%', height:'70%', margin: 10 }}>

  <Button onPress={() => this.AlertaDi(this.props.navigation)}
  title="Niños"/>

</View>

这是代码

import React from 'react';
import { 
  View, 
  StyleSheet,
  Button,
  Alert,
 } from 'react-native';

export default class TallerBotonDo extends React.Component {

 AlertaDi(){

      Alert.alert(
      'Alert Title',
      'Correcto',
      [
        {text: '==>', onPress: () => this.props.navigation.navigate('InicioBot')}
      ],
    );

 }
 render() {

  return (
   <View style={{width:'45%', height:'45%', margin: 10 }}>

    <Button onPress={() => this.AlertaDi(this.props.navigation)}
     title="Niños"/>

   </View>

  );

 }

}

这篇关于undefined 不是一个对象(评估 '_this2.props.navigation.navigate') Alert.alert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆