lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
624 stars 52 forks source link

Add wrapper around createRef with atom protocols #131

Closed lilactown closed 1 year ago

lilactown commented 1 year ago

Example usage:

(let [ref (helix.core/ref nil)]
  (reset! ref "foo")
  (prn @ref) ;; => "foo"
  (set! (.-current ref) "bar")
  (prn @ref) ;; => "bar"
  )
rome-user commented 1 year ago

I am experimenting with an implementation of this, but do we really want to add this?

The createRef is only really useful in class component, but that is rather awkward to use in Helix IMO, for three reasons:

  1. defcomponent makes several assumptions about state
  2. Class components cannot use hooks
  3. defcomponent does not have a clj-kondo linter, so one needs to ignore it or use def-catch-all, which is a worse DX than defnc.
lilactown commented 1 year ago

We found it useful when doing some interop between reagent and helix, where we needed to create a ref in a reagent component and pass it to a helix component. I agree that it shouldn't be used except in niche scenarios like that.