Fork me on GitHub

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


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
                            {:on-click #(dispatch [:purchase-plan])}) "Purchase Plan"]
             [:button (tw style/button [:text-base :bg-green-700
                                        :text-white :m-0
                          {:on-click #(dispatch [:login])})
              "Subscribe to Exclusive Content"


It uses the useElements function.


But I get the error:


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


How to call the hook correctly?


BTW a better place for this question would be #reagent


I’m converting the following code to cljs:

const {error, paymentMethod} = await stripe.createPaymentMethod({
      type: 'card',
      card: cardElement,
Here’s the cljs:
                (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?


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.


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


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.


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.


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.


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


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


I have the following code for Stripe integration:

(if card-element
                (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#
              [email protected]
This fails due to not being able to resolve deftest macro. I have seen 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

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

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