This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-28
Channels
- # announcements (2)
- # babashka (15)
- # beginners (13)
- # chlorine-clover (17)
- # cider (14)
- # clj-kondo (1)
- # cljfx (3)
- # clojure (21)
- # clojure-australia (2)
- # clojure-europe (3)
- # clojure-nl (4)
- # clojurescript (25)
- # core-async (7)
- # cursive (8)
- # datomic (4)
- # defnpodcast (17)
- # events (1)
- # honeysql (5)
- # jobs-discuss (18)
- # pathom (8)
- # polylith (6)
- # reagent (2)
- # reveal (1)
- # shadow-cljs (2)
- # spacemacs (12)
- # tools-deps (13)
- # xtdb (2)
https://cljdoc.org/d/reagent/reagent/1.0.0-alpha2/doc/frequently-asked-questions/how-do-i-use-react-s-refs- describes how to use a callback function on a :ref to take the DOM element set by Reagent and store a reference to it in an atom. When we're going the other way, and a hook from a React library is giving us a ref, is it correct to say that setting :ref to that ref will correctly cause the component to use the ref returned by the hook? Example of doing this with https://docs.dndkit.com/api-documentation/draggable, but I have a suspicions that the ref isn't getting set correctly, so I wanted to double-check my understanding:
(defn draggable []
(let [hook-ret (useDraggable (clj->js {:id "draggable"}))
{:keys [attributes listeners setNodeRef transform] :as converted-hook} (js->clj hook-ret)]
(r/as-element
[:div {:ref setNodeRef} (str "Draggable element: " converted-hook)])))