Fork me on GitHub
#shadow-cljs
<
2020-12-11
>
fsd20:12:27

Hi Everyone, I am a JavaScript dev (new to clojure), I am working with yarn package react-google-recaptcha. I am currently facing an issue to get back a token after verifying the recaptcha. If I do it in Javascript the onChange(value) function returns the token

function onChange(value) {
  console.log("Captcha value:", value);
}
 
ReactDOM.render(
  <ReCAPTCHA
    sitekey="Your client site key"
    onChange={onChange}
  />,
  document.body
);
But I try this in ClojureScript and I am getting nothing in the console
(defn onChange [value] 
       (println value)
)

($ ReCAPTCHA 
    { :sitekey "Your client site key" 
      :onChange #(onChange) })
(note $ is helix lib)
it tell me that wrong number of args (0) passed to onChange Can someone please tell where am I wrong?

dpsutton20:12:13

onChange expects an argument .`onChange={onChange}` means call the function onChange with the event. #(onchange) means is a shorthand for (fn [event] (onchange)) where you are not sending the event through. just do :onChange onChange which is exactly what the js version is doing

fsd20:12:54

Oh I see, (fn [event] (onchange)) anonymous function?

dpsutton20:12:38

that's what #(onchange) expands to in essence. and its calling a 1 arity function with no args. which is what your error is

dpsutton20:12:06

@singhamritpal49 also i think this is just a clojurescript question and so belongs in #clojurescript in the future

fsd20:12:23

Got it sorry for the mistake.

dpsutton20:12:47

no worries. its really to make sure the greatest number of people who could help actually see your question