Fork me on GitHub
#clojurescript
<
2021-02-07
>
khargawsh03:02:22

hi. i'm currently working on Bazel integration for clojurescript and have been looking at the compiler options. would it be possible to expose several of the --compile-opts as regular command line options as well?

Fredrik Andersson10:02:58

I'm looking for a memoize last function

zendevil11:02:32

I’m trying to use hooks in a react app like so:

(let [elements (useElements)] (if @s/user
             [:> div
              (e/load-stripe elements)
              [:> div (tw [:flex-row])
               [:> CardElement {:options (clj->js {:style {:base
                                                           {:fontSize "16px"
                                                            :color "#424770"
                                                            ;;:width "30em"
                                                            }
                                                           :invalid {:color "#9e2146"}}})}]
               [:button (tw style/button [:bg-green-700
                                          :text-white
                                          :text-sm]
                            {:on-click #(dispatch [:purchase-plan])}) "Purchase Plan"]
               ]
              ]
             [:button (tw style/button [:text-base :bg-green-700
                                        :text-white :m-0
                                        :px-6
                                        :py-5
                                        ]
                          {:on-click #(dispatch [:login])})
              "Subscribe to Exclusive Content"
              ]))

zendevil11:02:45

It uses the useElements function.

zendevil12:02:09

But I get the error:

zendevil12:02:12

react-dom.development.js:14747 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app

zendevil12:02:29

How to call the hook correctly?

p-himik12:02:48

BTW a better place for this question would be #reagent

zendevil12:02:27

I’m converting the following code to cljs:

const {error, paymentMethod} = await stripe.createPaymentMethod({
      type: 'card',
      card: cardElement,
    });
Here’s the cljs:
(go
                (prn "stripe is " stripe)
                (let [[error payment-method]
                      (<! (.createPaymentMethod stripe {:type "card" :card card-element}))]
                  (prn "error is " error)
                  (js/console.log "payment method is " payment-method)))
But am getting the error:
IntegrationError: Invalid value for createPaymentMethod: type should be string. You specified: undefined.
How to fix this?

p-himik12:02:19

createPaymentMethod expects a JS object but you're giving it a CLJS map. If card-element is some JS value, then it can be fixed by just adding #js in front of the map literal.

p-himik12:02:34

Also, I don't think that go and <! work with JS functions that return promises.

p-himik12:02:03

There are many ways to work with async JS functions in CLJS, one of them would be to just use the promise API via interop.

p-himik12:02:59

Finally, you're trying to destructure a JS object as if it were an array. It won't work - you will have to use JS interop for that.

zendevil16:02:03

after adding the #js in front of the map, I’m getting the following error:

IntegrationError: Please use the same instance of `Stripe` you used to create this Element to create your Source or Token.

zendevil16:02:13

even though I have a single stripe object that I’m using

p-himik16:02:07

No idea, I don't have clue what "Stripe" is or how it works and why.

zendevil17:02:42

I have the following code for Stripe integration:

(if card-element
              (go
                (prn "stripe is " stripe)
                (let [error-payment-method
                      (<! (.createPaymentMethod stripe #js {:type "card" :card card-element}))]
                  (prn "error is " error-payment-method)
                  ))
              (prn "card element is nil")
              )
But this gives me the error
IntegrationError: Please use the same instance of `Stripe` you used to create this Element to create your Source or Token.
How to fix this error?

Milan Munzar19:02:42

Hey, 🙂 I am trying to define a test support macro for a common pattern when testing with go blocks. Could somebody point me in the right direction? This is the pseudocode:

(defmacro deftest-go
  [name & body]
  `(cljs.test.deftest ~name
     (cljs.test.async done#
            (cljs.core.async/go
              [email protected]
              (done#)))))
This fails due to not being able to resolve deftest macro. I have seen http://blog.fogus.me/2010/09/03/monkeying-with-clojures-deftest/) a different approach, which uses deftest implementation. Thank you!

Milan Munzar20:02:54

I think I have done it. The first implementation of macro file is:

(ns commons.utils.test-support
  (:require
    [clojure.test]))


(defonce ^:dynamic
  *load-tests* true)

(defmacro deftest-go
  [name & body]
  (when *load-tests*
    `(def ~(vary-meta name assoc :test `(fn []
                                          (cljs.test/async done#
                                            (cljs.core.async/go
                                              [email protected]
                                              (done#)))))
          (fn [] (clojure.test.test-var (var ~name))))))