0

I'd like to know how I'm exporting my object incorrectly? In my view, I'm seeing this error: ./src/context.js Attempted import error: 'detailProduct' is not exported from './data'.

In the console I indeed see the objects being populated correctly but for some reason it won't render my view because of the aforementioned error. What am I doing wrong?

export const storeProducts = [
  {
    id: 1,
    title: "Crusk Beanie (black)",
    img: "img/CruskipBlackBeanie.png",
    price: 1,
    company: "Cruskip",
    info:
        "Winter's right around the corner, get your beanie today!",
    inCart: false,
    count: 0,
    total: 0
  },
  {
    id: 3,
    title: "Cruskip Short Sleeve T-shirt",
    img: "img/CruskipWhiteShortSleeve.jpg",
    price: 8,
    company: "Cruskip",
    info:
        "Exclusive Cruskip white t-shirts!",
    inCart: false,
    count: 0,
    total: 0
  },
];

let detailProduct = {};

storeProducts.forEach((arrayItem) => {
  detailProduct = {
    id: arrayItem.id,
    title: arrayItem.title,
    img: arrayItem.img,
    price: arrayItem.price,
    company: arrayItem.company,
    info: arrayItem.info,
    inCart: arrayItem.inCart,
    count: arrayItem.count,
    total: arrayItem.total
  };
  console.log(arrayItem);
});

export default detailProduct;
luvs2spuge
  • 75
  • 5

1 Answers1

2

You're likely importing it using braces, but you can't do that for default exports:

// This will work
import detailProduct from './data';

// This won't
import { detailProduct } from '.data';

On the other hand, since storeProducts is a named export, it works the other way around:

// This will work
import { storeProducts } from './data';
// This won't
import storeProducts from './data';
Nick
  • 16,066
  • 3
  • 16
  • 32