Fork me on GitHub
#reagent
<
2023-02-09
>
Ryan17:02:55

Hey having a spot of trouble moving a js function around.. getting a js object from a primereact component that contains an onClick handler in the payload.. and I need to map it to the onClick of the element its generating. Called thusly:

[:> TabPanel {:headerTemplate #(icon-tab-button % "mdiAccountFilter" "Filter Patients")}


(defn icon-tab-button [options icon label]
  (let [click-handler (:onClick options)]
    (reagent.core/as-element [:a {:on-click click-handler :role "tab" :class "p-tabview-nav-link"} [:span.p-tabview-title [pnx-icon icon "1rem"] label]])))

Ryan17:02:28

I can confirm the props are making it to the icon-tab-button function.. its there as a #js literal

p-himik17:02:40

And what is the trouble exactly?

Ryan17:02:31

Im not sure the correct syntax to set the javascript click handler in the options var to the anchor’s on-click, the code as supplied does not do the trick.

p-himik17:02:20

What does "does not do the trick" mean? Does nothing happen when you click it? Or is there an error? Does something else happen?

p-himik17:02:03

Ah, options is a JS object? Then replace (:onClick options) with (.-onClick ^js options).

🙏 2
Ryan17:02:06

Oh of course, there’s no console error and nothing happens when the tab is clicked

Ryan17:02:33

Let me try that syntax

Ryan17:02:54

That did exactly the trick. Thanks so much!

👍 2