0

I'm trying to create an RN Object with a constructor passing json object but I'm getting "ReferenceError: Can't find variable: Product".

Product.js

export default class Product {
    constructor(product) {
        this.name = product.name
        this.items = product.Items
        this.price = product.Price
        this.productID = product.ProductID 
        this.medias = product.Medias
        this.imageSmall = BASE_IMAGES_URL + product.MediaSmall
        this.imageLarge = this.getImageLarge(product.Medias)
    }
}

PDP.js

import { Product } from '../models/Product'
class PDP extends Component {
 render() {

    var imagesProd = [];
    var product = new Product(this.props.navigation.state.params.currentProduct);
      ....
}
}

the problem is with new Product() using directly this.props.navigation.state.params.currentProductworks fine.

EDIT

After your tips, I changed the import to import Product from '../models/Product'but I'm getting

TypeError: TypeError: TypeError: TypeError: undefined is not a constructor (evaluating 'new P.default(s)')

Ladessa
  • 985
  • 4
  • 24
  • 50

2 Answers2

1

The problem is with your import. You used a default export in Product class so your import should be

import Product from '../models/Product'
Mahdi N
  • 2,128
  • 3
  • 17
  • 38
0

The first line in PDP.js should be import Product from '../models/Product'

Take a look here for few details about import. When should I use curly braces for ES6 import?

Afik Menashe
  • 77
  • 1
  • 1
  • 8