我是新来的反应母语和我有一个硬加载的应用程序。一切工作,而我是用来自JSON文件直接导入数据的工作,然后我决定来动态实现它使用JSON服务器模块,同时使用终极版,但只要我启动应用程序,我收到此错误信息。
我做了一些搜索和它显然是关系到ES6语法。举例来说,我看了一下这家伙的回答:Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null
我不是在渲染方法使用任何箭头的功能。我不知道还有什么可能是问题。任何帮助,将不胜感激 。
[![import React, { Component } from 'react';
import { ScrollView, View, Text } from 'react-native';
import { Card } from 'react-native-elements';
import { ListItem} from 'react-native-elements';
import { connect } from 'react-redux';
import { baseUrl } from '../../shared/baseUrl';
const mapStateToProps = (state) => {
return {
dishes: state.dishes,
comments: state.comments,
promotions: state.promotions,
leaders: state.leaders
}
}
function RenderItem(props){
const item = props.item;
if(item != null){
return(
<Card
featuredTitle={item.name}
featuredSubtitle={item.designation}
image={{ uri: baseUrl + item.image }}>
<Text style={{ margin: 10 }}>
{item.description}
</Text>
</Card>
)
}
}
class HomeScreen extends Component {
static navigationOptions = {
title: 'Accueil'
}
render() {
return (
<ScrollView>
<RenderItem item={this.props.dishes.dishes.filter((dish) => dish.featured)\[0\]} />
<RenderItem item={this.props.promotions.promotions.filter((promo) => promo.featured)\[0\]} />
<RenderItem item={this.props.leaders.leaders.filter((leader) => leader.featured)\[0\]} />
</ScrollView>
);
}
}
export default connect(mapStateToProps)(HomeScreen);
export const baseUrl = 'http://<ip-address>:3001';
看来你的renderItem没有返回数据,你没有任何逻辑来解释它。你还没有定义项。尝试这个...
function RenderItem(props) {
const item = props.item;
if (item != null) {
return(
<Card
featuredTitle={item.name}
featuredSubtitle={item.designation}
image={{uri: baseUrl + item.image}}>
<Text
style={{margin: 10}}>
{item.description}</Text>
</Card>
);
}
else {
return(<View></View>);
}
}