Fork me on GitHub
#cljsrn
<
2023-08-06
>
Nim Sadeh17:08:27

I am trying to use a rn-sliding-up-panel in a ClojureScript app, but not sure how to convert this part:

<SlidingUpPanel ref={(c) => this._panel = c}>
The closes thing I can come up with is something like
:> SlidingUpPanel {:ref (js->clj #{(c) => this._panel = c})}

djanus08:08:52

assuming you’re using reagent, you can have a https://github.com/reagent-project/reagent/blob/master/doc/CreatingReagentComponents.md#form-2--a-function-returning-a-function that creates an atom in the outer-fn:

(defn your-component []
  (let [ref (atom nil)]
    ;; you can pass @ref to other stuff that might need it
    (fn []
      [:> SlidingUpPanel {:ref #(reset! ref %)}])))
alternatively, you could use (React/createRef), which is just
(def ref (react/createRef))

;; use (.-current ref) to access the component from elsewhere

(defn your-component []
  [:> SlidingUpPanel {:ref ref}])