React Native-导航问题“未定义不是对象(t.props.navigation.navigate)”

时间:2019-06-12 15:02:17

标签: reactjs api react-native react-navigation react-native-paper

我当前正在创建一个小的Magic the Gathering项目,该项目将从API提取卡数据并将其插入我的应用中。我先获取了诸如name之类的数据,但随后单击名称时,我想查看更多信息,例如卡说明等。但是,我一直遇到以下错误:“未定义不是对象(this.props.navigation.navigate)”。我该如何解决?

import React from 'react';
import { Paragraph, Card, Avatar, Button } from "react-native-paper";
import { Image, View, StyleSheet, AsyncStorage } from 'react-native';


export default class CardProfile extends React.Component {
  render() {
    const { props } = this.props
    const card = props["state"].params
    const img = card.imageUrl
    return (
      <View style={styles.container}>

          <View style={styles.cardinfo}>

                    <Card>
                        <View style={styles.title}>
                            <Card.Title
                                title={card.name}
                                subtitle={card.colors}
                            />
                        </View>

                        <View style={styles.content}>
                            <Card.Content>
                                <Paragraph>{card.text}</Paragraph>
                                <Image
                                    style={styles.img}
                                    source={{ uri: img }}
                                />
                            </Card.Content>
                        </View>

                        <View style={styles.actions}>
                            <Card.Actions>
                                <Button onPress={() => {
                                    // create a function that saves your data asyncronously
                                    _storeData = async () => {
                                        try {
                                            await AsyncStorage.setItem('@Card', this.state.card);
                                        } catch (error) {
                                            console.log("Could not save!", error);
                                        }
                                    }
                                }}>add card</Button>
                            </Card.Actions>
                        </View>

                    </Card>

                </View>
            </View>
        );
    }
}


输出应该是我要查看的所选卡的卡信息。

1 个答案:

答案 0 :(得分:0)

您在代码中的哪里使用this.props.navigation.navigate?您确定要调用的组件已通过navigation作为道具吗?