Listview 类型错误:null不是对象(正在计算';this.state.isLoading';)
我已经初始化了状态,但是发生了什么Listview 类型错误:null不是对象(正在计算';this.state.isLoading';),listview,react-native,react-native-android,Listview,React Native,React Native Android,我已经初始化了状态,但是发生了什么 已经进口了必需品 import React, { Component } from 'react'; import { AppRegistry, FlatList, StyleSheet, ActivityIndicator ,ListView , Alert , Text, View } from 'react-native'; export default class FlatListBasics extends Component { co
- 已经进口了必需品
}) }) .catch((错误)=>{ 控制台错误(error) })); } render(){ 如果(!this.state.isLoading){ 返回( ); } 否则{ 返回( {item.body} /> ); }import React, { Component } from 'react'; import { AppRegistry, FlatList, StyleSheet, ActivityIndicator ,ListView , Alert , Text, View } from 'react-native'; export default class FlatListBasics extends Component { constructor(props) { super(props); var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); this.states = { isLoading : true , dataSource: {} }; } componentDidMount = () => { fetch('https://jsonplaceholder.typicode.com/posts/1', { method: 'GET' , }) .then((response) => response.json()) .then((responseJson) => { console.log(responseJson); Alert.alert("done"); this.setState({ data: responseJson , isLoading: false
} } const styles = StyleSheet.create({ container: { flex: 1, paddingTop: 22 }, item: { padding: 15, borderBottomWidth: 2 , borderBottomColor: '#888888' , fontSize: 18, height: 54, }, })
- 我刚刚给这个州打了电话
- 为什么会发生这种事?现在有人
this.state
拼写为this.states
...
this.states = {
isLoading : true ,
dataSource: {}
};...
将this.states
更改为this.state
:)