async updated()

in client/src/pages/product.js [45:70]


  async updated() {
    const prevItem = this.state.productItem;
    let productItem;

    // Fetch the product
    if (this.productId) {
      productItem = await getProduct(this.productId);

      this.state = {
        ...this.state,
        status: 'loaded',
        productItem,
      };

      // If there was an error, make sure this is captured.
      if (productItem?.apiError) {
        this.state.apiError = productItem.apiError;
        this.requestUpdate(); // BUG(glasnt): with this, the page API loops. Without, it doesn't update at all.
      }
      // Only update if the previously loaded product
      // is different than the requested product
      if (prevItem?.id !== this.productId) {
        this.requestUpdate();
      }
    }
  }