简体   繁体   English

我无法在 React Native 中获得 map 工作——未定义不是 function(靠近“..._products.default.map...”)

[英]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.

相关问题 React native Undefined 不是函数(&#39;...data.map...&#39; 附近) - React native Undefined is not a function (near '...data.map...') React Native TypeError undefined is not a function(靠近'...data.map...') - React Native TypeError undefined is not a function (near '…data.map…') Undefined 不是 function('...item.map...' 附近)-React Native 搜索栏 - Undefined is not a function (near '…item.map…')-React Native search bar TypeError: undefined is not a function (near &#39;...productsCtg.map...&#39;) 反应原生 - TypeError: undefined is not a function (near '...productsCtg.map...') react native (React Native) passing props with Map function undefined is not a function (near '...resturants.map...') - (React Native) passing props with Map function undefined is not a function (near '...resturants.map...') 未定义不是 function(靠近'... map ...') - Undefined is not a function (near '… map …') React-Native - 错误类型错误:未定义不是 function(靠近'...object.Z1EZ8DC8ED512449E) - React-Native - ERROR TypeError: undefined is not a function (near '...object.map...') React - “TypeError: undefined is not a function (near '...formFields.map...')” - React - “TypeError: undefined is not a function (near '…formFields.map…')” undefined 不是 function ('...this.state.results.map...' 附近) - undefined is not a function (near '…this.state.results.map…') 反应原生中的地图功能 - map function in react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM