0
与react-native
很新的,被卡住的“元素类型是无效的错误”阵营本土元素类型是无效的 - 出口
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
ActivityIndicatorIOS,
View
} from 'react-native';
export default class SplashWalls extends Component {
constructor(props) {
super(props);
this.state = {
wallsJSON: [],
isLoading: true
};
}
fetchWallsJSON() {
var url = 'https://unsplash.it/list';
fetch(url)
.then(response => response.json())
.then(jsonData => {
console.log(jsonData);
this.setState({isLoading: false}); //update isLoading
})
.catch(error => console.log('Fetch error ' + error));
}
componentDidMount() {
this.fetchWallsJSON();
}
render() {
var {isLoading} = this.state;
if(isLoading)
return this.renderLoadingMessage();
else
return this.renderResults();
}
renderLoadingMessage() {
return (
<View style={styles.loadingContainer}>
<ActivityIndicatorIOS
animating={true}
color={'#fff'}
size={'small'}
style={{margin: 15}} />
<Text style={{color: '#fff'}}>Contacting Unsplash</Text>
</View>
);
}
renderResults() {
return (
<View>
<Text>
Data loaded
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
loadingContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#000'
}
});
AppRegistry.registerComponent('SplashWalls',() => SplashWalls);
错误状态:
元素类型无效:预期字符串(对于内置组件) 或类/函数(用于复合组件),但得到:未定义。您 可能忘记将您的组件从其定义的文件中导出。
检查'SplashWalls'的Render方法。
任何想法?
尝试结合您的渲染方法,在构造函数中:'这一点。 renderLoadingMessage = this。 renderLoadingMessage.bind(this)',第二种方法相同。 –
什么是你的项目文件夹的名称?只有SplashWalls? –