[英]I cant get .map work in React Native -- undefined is not a function (near '..._products.default.map...')
I just started learning React Native but i cant figure out how to use.map in it and i get this error我刚开始学习 React Native,但我不知道如何在其中使用 .map,我收到此错误
undefined is not a function (near '..._products.default.map...') undefined 不是 function(靠近“..._products.default.map...”)
// products.js
const products = [
{
_id: "1",
name: "Blue and Red",
image: "./images/Epic Venge logo.png",
description: "Blue and Red",
brand: "Old",
category: "Logos",
price: 19.99,
countInStock: 10,
rating: 3.5,
numReviews: 12,
},
];
// HomePage.js
import products from "../products";
import ProductCard from "../components/ProductCard";
export default function HomePage({ navigation }) {
return (
<DismissKeyboard>
<View>
<Header />
{products.map((product) => (
<View key={product._id}>
<ProductCard product={product} />
</View>
))}
</View>
);
}
// ProductPage.js
export default function ProductPage({ navigation }) {
return (
<SafeAreaView>
<Text onPress={() => navigation.push("Home")}>It Worked!!</Text>
</SafeAreaView>
);
}
You are not exporting products.js您没有导出 products.js
// products.js
export const products = [
{
_id: "1",
name: "Blue and Red",
image: "./images/Epic Venge logo.png",
description: "Blue and Red",
brand: "Old",
category: "Logos",
price: 19.99,
countInStock: 10,
rating: 3.5,
numReviews: 12,
},
];
then import it like so然后像这样导入
import { products } from "./products";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.