Reactjs console.error:";“未处理的错误”;网络错误:网络请求失败
在我的react本机应用程序中,出现了这样一个错误红色屏幕 当我在设备(真实设备或模拟器)中禁用internet连接或出现任何类型的服务器错误时,就会发生此错误 我将按照下面的文档信息“处理”apollo和react native的错误: 在我的代码中有如下内容:Reactjs console.error:";“未处理的错误”;网络错误:网络请求失败,reactjs,react-native,apollo,react-apollo,apollo-client,Reactjs,React Native,Apollo,React Apollo,Apollo Client,在我的react本机应用程序中,出现了这样一个错误红色屏幕 当我在设备(真实设备或模拟器)中禁用internet连接或出现任何类型的服务器错误时,就会发生此错误 我将按照下面的文档信息“处理”apollo和react native的错误: 在我的代码中有如下内容: import React, { Component } from 'react'; import { Platform, StyleSheet, Text, ActivityIndicator,
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
ActivityIndicator,
View,
FlatList,
TouchableHighlight,
TextInput,
Button,
} from 'react-native';
import PropTypes from 'prop-types';
import { graphql, compose } from 'react-apollo';
import ZONES_QUERY from '../graphql/zones.query'
class ZonesScreen extends Component {
render() {
const { zones, loading, error } = this.props;
if (loading) {
return (
<ActivityIndicator style={styles.activityIndicator} size='large' />
)
} else if (error) {
return (
<View style={styles.container}>
<Text>Unexcpeted Error</Text>
<Button title="retry" onPress={() => { this.props.refetch() }}></Button>
</View>
)
} else {
return (
<View
style={styles.container}>
<FlatList
data={zones}
renderItem={({ item }) => ZoneRenderItem(item)}
keyExtractor={this.keyExtractor}
/>
</View>
)
}
}
//HELPER FUNCTIONS
keyExtractor = item => item._id;
}
ZonesScreen.propTypes = {
refetch: PropTypes.func,
}
const zonesQuery = graphql(ZONES_QUERY, {
options: {
forceFetch: true,
fetchPolicy: 'network-only',
notifyOnNetworkStatusChange: true,
},
props: ({ data: { loading, getRoutes, error, refetch } }) => ({
loading,
zones: getRoutes,
refetch,
error,
}),
})
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#eee',
},
activityIndicator: {
flex: 1,
justifyContent: 'center',
},
});
export default compose(
zonesQuery,
)(ZonesScreen)
const errorLink = onError(({ graphQLErrors, networkError}) => {
console.log("ERROR: " +networkError)
})
const client = new ApolloClient({
link: concat(errorLink, httpLink),
cache: new InMemoryCache(),
});
我有两个屏幕
屏幕A:它确实包含转到屏幕B的按钮。
屏幕B:包含区域列表(此信息从服务器获取)
下面是重现此错误的步骤:
- 我打开应用程序。(我看到屏幕A)。我从设备上禁用internet连接,我点击按钮进入屏幕B