This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-21
Channels
- # announcements (9)
- # beginners (222)
- # boot (11)
- # calva (40)
- # cider (1)
- # clj-kondo (10)
- # cljs-dev (1)
- # cljsrn (8)
- # clojars (4)
- # clojure (50)
- # clojure-dev (4)
- # clojure-ecuador (1)
- # clojure-europe (4)
- # clojure-italy (3)
- # clojure-madison (2)
- # clojure-nl (26)
- # clojure-spec (86)
- # clojure-uk (34)
- # clojurescript (11)
- # clr (1)
- # cursive (46)
- # datomic (19)
- # emacs (4)
- # events (1)
- # fulcro (22)
- # graalvm (4)
- # graphql (2)
- # jobs-discuss (40)
- # leiningen (10)
- # luminus (6)
- # nrepl (7)
- # off-topic (18)
- # onyx (6)
- # overtone (1)
- # pedestal (2)
- # planck (1)
- # re-frame (5)
- # reagent (3)
- # reitit (8)
- # rewrite-clj (2)
- # shadow-cljs (139)
- # sql (4)
- # tools-deps (42)
@lilactown i have a div which i render with a ref
. in component-did-mount
, i want to get the height and width of the div using the ref
and use those values to set the dimensions of a canvas which is nested within the div. problem is, the height and width of the div in component-did-mount
are initially slightly off. if i instead, wait ~100ms, and then get the dimensions of the div, everything will be correct.
here's a code excerpt, if you'd like to take a look:
([attributes props]
(let [node (atom nil)
sketch (atom nil)
handler (atom nil)]
(r/create-class
{:component-did-mount
(fn []
(println "drawing mounted")
(let [s (-> props (assoc :node @node) ->sketch)]
(reset! sketch s)
(when-let [on-resize (:on-resize props)]
(let [rh (->resize-handler @node on-resize s)]
(.addEventListener js/window "resize" rh)
(reset! handler rh))))
#_(js/setTimeout
#(let [s (-> props (assoc :node @node) ->sketch)]
(reset! sketch s)
(when-let [on-resize (:on-resize props)]
(let [rh (->resize-handler @node on-resize s)]
(.addEventListener js/window "resize" rh)
(reset! handler rh))))
100))
:reagent-render
(fn [] [:div (assoc attributes :ref (partial reset! node))])})))