title: ReactJs functions that need refractoring (if possible)
body: <p>I have a few functions I've written for a basic e-commerce store, but both seem a little lengthy to me. </p>
  
  <p>Perhaps someone out there has some suggestions on how I might be able to refractor them?</p>
  
  <p>Cheers.</p>
  
  <p>1 - a function that had adds an item to the cart or wishlist based on an action:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> addToFunnelHandler = (uuid, price, title, action) =&gt; {
    let productToAdd = {}
        productToAdd.uuid = uuid
        productToAdd.price = price
        productToAdd.title = title
        if (action === 'bag') {
          let productsInBag = [...this.state.productsInBag]
          productsInBag.push(productToAdd)
          this.setState({ productsInBag: productsInBag, bagCount: this.state.bagCount + 1, bagTotal: this.state.bagTotal + price })
      } else if (action === 'wishlist') {
          let productsInWishlist = [...this.state.productsInWishlist]
          productsInWishlist.push(productToAdd)
          this.setState({ productsInWishlist: productsInWishlist, wishlistCount: this.state.wishlistCount + 1})
      }
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>2 - Same but in reverse, removing an item from the funnel:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>removeFromFunnelHandler = (uuid, price, action) =&gt; {
      if (action === 'bag') {
        let productsInBag = [...this.state.productsInBag]
        productsInBag.forEach((product, index) =&gt; {
        if (product.uuid === uuid) { productsInBag.splice(index, 1) }
       })
      this.setState({ productsInBag: productsInBag, bagCount: this.state.bagCount - 1, bagTotal: this.state.bagTotal - price  })
    } else if (action === 'wishlist') {
        let productsInWishlist = [...this.state.productsInWishlist]
        productsInWishlist.forEach( (product, index) =&gt; {
        if (product.uuid === uuid) { productsInWishlist.splice(index, 1) }
       })
      this.setState({ productsInWishlist: productsInWishlist, wishlistCount: this.state.wishlistCount - 1 })
      }
    }</code></pre>
  </div>
  </div>
  </p>