0
我在React Native中收到以下錯誤,並查看了多個有相同問題的人的帖子,米仍然沒有任何運氣解決這個問題。不確定是什麼原因造成這個問題。React Native Error「未定義不是對象(正在評估'_this2.props.navigation.navigate')」
這裏是我的APP.JS CODE
import * as Expo from 'expo';
import React from 'react';
import { StyleSheet, Text, AppRegistry, View, Image, TouchableOpacity, FlatList } from 'react-native';
import { StackNavigator } from 'react-navigation';
import { withNavigation } from 'react-navigation';
import HostClient from './app/Views/HostClientView';
import ClientQueue from './app/Views/ClientQueue';
import SearchBarr from './app/components/Searchbar';
export default class App extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
return (
<Image style = {styles.container} source={require('./app/images/jukebox-background.jpg')} resizeMode="cover">
<View>
<HostClient />
</View>
</Image>
);
}
const SimpleApp = StackNavigator({
HostClientView: { screen: HostClient },
ClientQueueView: { screen: ClientQueue},
});
這裏是我的HOSTCLIENT.JS這是我提出的主要查看所有組件
import React from 'react';
import { StyleSheet, Text, AppRegistry, View, Image, TouchableOpacity,
FlatList } from 'react-native';
import Host from '../../components/Host/Host.js';
import UserRequest from '../../components/UserRequest/UserRequest.js';
import { StackNavigator } from 'react-navigation';
import Button from 'react-native-button';
export default class HostClient extends React.Component {
render() {
return (
<View>
<Host />
<UserRequest />
<Button style = {styles.button} title="ClientQueueView"
onPress={() => this.props.navigation.navigate('ClientQueueView') }> <Image style = {styles.turntable} source={require('../../images/vinyl2.png')} resizeMode="contain"/>
</Button>
</View>
);
}
}
最後這裏是user.js的文件
// Request Component
import React, { Component } from 'react';
import { StyleSheet, AppRegistry, Text, View, Image } from 'react-
native';
import Button from 'react-native-button';
import { StackNavigator } from 'react-navigation';
export default class UserRequest extends Component {
static navigationOptions = ({navigation}) => {
const {state, navigate} = navigation;
return {
title: 'Noah Testing'
};
};
constructor() {
super();
this.state = {
address: [],
refreshing: false,
page: 1,
lastPage: 1,
loading: true,
listOpacity: 0,
};
}
render() {
return (
<View >
<Text > Request </Text>
<Button title="ClientQueueView"
onPress={() => this.props.navigation.navigate('ClientQueueView') }> <Image style = {styles.turntable} source={require('../../images/vinyl2.png')} resizeMode="contain"/>
</Button>
</View>
);
}
}
那麼哪條線正好導致錯誤? –
想通了。羅特的一般錯誤。 –