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)')

2 Answers 2

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'
Sign up to request clarification or add additional context in comments.

1 Comment

thanks! I changed the import but now I'm getting other error. (EDITED with more details)
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?

1 Comment

thanks! I changed the import but now I'm getting other error. (EDITED with more details)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.