reagent

Ryan 2023-02-09T17:36:55.584439Z

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]])))

Ryan 2023-02-09T17:38:28.526569Z

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

p-himik 2023-02-09T17:38:40.588699Z

And what is the trouble exactly?

Ryan 2023-02-09T17:39:31.040739Z

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-himik 2023-02-09T17:40:20.062839Z

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-himik 2023-02-09T17:41:03.180679Z

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

🙏 1
Ryan 2023-02-09T17:41:06.690709Z

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

Ryan 2023-02-09T17:42:33.853919Z

Let me try that syntax

Ryan 2023-02-09T17:44:54.214349Z

That did exactly the trick. Thanks so much!

👍 1