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.
That makes sense. I will give it a try. Thx
That worked!! Thanks again
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?I don't think you're rerunning your query when something changes
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)))