我是本机反应的新手,我试图将 reduxstore 连接到我的应用程序,以便我的 Menu 组件可以获取菜肴。我已经尝试了所有检查导出错误的方法,但我找不到路线丢失的地方。请帮助我被卡住了
菜单组件.js
import React, { Component } from "react";
import { FlatList } from "react-native";
import { Tile } from "react-native-elements";
import { connect } from "react-redux";
import { baseUrl } from "../shared/baseUrl";
const mapStateToProps = state => {
return {
dishes: state.dishes
}
};
class Menu extends Component {
static navigationOptions = {
title: "Menu"
};
render() {
const renderMenuItem = ({ item, index }) => {
return (
<Tile
key={index}
title={item.name}
subtitle={item.description}
featured
onPress={() => navigate("Dishdetail", { dishId: item.id })}
imageSrc={{ uri: baseUrl + item.image }}
/>
);
};
const { navigate } = this.props.navigation;
return (
<FlatList
data={this.props.dishes.dishes}
renderItem={renderMenuItem}
keyExtractor={item => item.id.toString()}
/>
);
}
}
export default connect(mapStateToProps)(Menu);
智慧大石
相关分类