This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-19
Channels
- # aleph (5)
- # announcements (1)
- # babashka (5)
- # beginners (123)
- # biff (9)
- # calva (8)
- # cider (1)
- # clj-on-windows (8)
- # clojure (20)
- # clojure-europe (7)
- # clojure-hungary (3)
- # clojure-norway (1)
- # clojure-sweden (32)
- # clojurescript (2)
- # core-async (2)
- # emacs (6)
- # events (3)
- # fulcro (30)
- # graphql (4)
- # gratitude (3)
- # helix (10)
- # honeysql (7)
- # introduce-yourself (11)
- # kaocha (1)
- # malli (16)
- # matcher-combinators (1)
- # off-topic (7)
- # portal (1)
- # re-frame (12)
- # reagent (3)
- # ring (7)
- # scittle (3)
- # shadow-cljs (1)
- # sql (1)
- # tools-deps (8)
What am I missing? My canvas renders ok but the height and width from the parent have no effect
(defnc Canvas [height, width]
(let [canvas (hooks/use-ref nil)]
(hooks/use-effect
:always
(let [context (.. canvas -current (getContext "2d"))]
(js/console.log context)
))
(d/div
(d/canvas {:id "canvas"
:ref canvas
:style {:height height :width width :background-color "blue"}})))
)
(defnc sandbox []
($ Canvas 900 500))
(On mobile) defnc expects a map as the argument. So do [{:keys [width height]}
and then pass then as a map in the parent.
No problem :)
Hi! Does anyone has tried the useSyncExternalStore
with datascript
? I have a mistake with this:
defn use-datascript [query]
(let [value (dts/q query (dts/db dts-conn))
[subscribe snapshot] (hooks/use-memo [query value]
[(fn [f]
(let [key (random-uuid)]
(dts/listen! dts-conn key f)
(fn [] (dts/unlisten! dts-conn key))))
(fn [] value)])]
(react/useSyncExternalStore subscribe snapshot))
When a transact!
occur, the hook is not played 😕 . Any idea?when f
is called by dts/listen
, react then calls the snapshot
function. if the snapshot returns the same value, it doesn't re-render your component
in this case, snapshot
always returns the value that the component was last rendered with, so it's likely it won't have changed unless something else re-rendered your component
Thanks for your explication. I have update the hook:
(defn use-datascript [query & opts]
(let [db (react/useSyncExternalStore
(react/useCallback (fn [listener]
(let [key (random-uuid)]
(dts/listen! dts-conn key listener)
(fn [] (dts/unlisten! dts-conn key))))
#js [dts-conn])
(react/useCallback (fn [] (dts/db dts-conn))
#js [dts-conn]))]
(apply dts/q query db opts)))