Fork me on GitHub
#helix
<
2021-07-08
>
jjttjj16:07:51

How can I access a the underlying dom node from within a component? I'm trying to wrap a vanilla js library in a component nevermind, I got it!

3
lilactown17:07:21

assuming this is what you found but for the benefit of others 🙂

👍 3
jjttjj18:07:37

Thanks! And, also for future users, the general helix pattern is this:

(defnc my-lib-component [{:keys [opts] :as props}]
  (let [ref (hooks/use-ref nil)
        d   (d/div {:ref ref})]
    (hooks/use-effect []
      (MyLibConstructor. opts @ref))
    d))
Where my lib-constructor is a vanilla js lib that takes a dom node in the constructor

dominicm20:07:04

@jjttjj You can do (hooks/use-effect :once ...) instead too which reads a little nicer.

👍 3