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?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
@singhamritpal49 also i think this is just a clojurescript question and so belongs in #clojurescript in the future
Oh I see, (fn [event] (onchange))
anonymous function?
that's what #(onchange)
expands to in essence. and its calling a 1 arity function with no args. which is what your error is
Got it sorry for the mistake.
no worries. its really to make sure the greatest number of people who could help actually see your question
👍