shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
fsd 2020-12-11T20:28:27.423200Z

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?

dpsutton 2020-12-11T20:34:13.424900Z

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

dpsutton 2020-12-11T20:40:06.425400Z

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

fsd 2020-12-11T20:44:54.425500Z

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

dpsutton 2020-12-11T20:45:38.425700Z

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

fsd 2020-12-11T20:46:23.425900Z

Got it sorry for the mistake.

dpsutton 2020-12-11T20:47:47.426100Z

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

fsd 2020-12-11T20:49:41.426300Z

👍