helix

2021-07-08T16:55:51.158900Z

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!

👍🏻 1
lilactown 2021-07-08T17:25:10.159500Z

https://reactjs.org/docs/refs-and-the-dom.html

lilactown 2021-07-08T17:25:21.159900Z

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

👍 1
2021-07-08T18:20:37.161200Z

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

dominicm 2021-07-08T20:54:04.162Z

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

👍 1