This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-01
Channels
- # announcements (7)
- # babashka (10)
- # beginners (60)
- # clerk (4)
- # clojure (19)
- # clojure-conj (5)
- # clojure-europe (48)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-uk (2)
- # clojurescript (12)
- # conjure (2)
- # core-async (24)
- # cursive (3)
- # datalevin (18)
- # events (1)
- # figwheel-main (5)
- # fulcro (22)
- # honeysql (29)
- # hyperfiddle (60)
- # jobs (3)
- # leiningen (18)
- # lsp (47)
- # meander (21)
- # missionary (6)
- # off-topic (35)
- # reagent (14)
- # remote-jobs (1)
- # ring (1)
- # shadow-cljs (32)
- # sql (10)
- # transit (12)
using clojurescript with react, instead of component-did-mount I want only when a component has focus on and it is on screen, not when it mounts: So (keyboard-listener-on) is only active when focus is on please
(defn bool-field [{:keys [field-id input-data form-messages current-page index regenerate-display-fields on-submit]}]
(let [text-val (r/atom (:value (get input-data (keyword field-id))))]
(r/create-class
{:component-did-mount (fn [_this]
(println (str "binding start " field-id))
(keyboard-listener-on!))
:component-will-unmount (fn [_this]
(println (str "unmount " field-id))
(keyboard-listener-off!))
:reagent-render (fn [{:keys [field-id form-messages on-submit regenerate-display-fields
field index theme-data current-page input-data]}]
[v-box
:width "100%"
:align :center
:justify :center
:children [...]])})))
That's a more generic problem of JS - not even React, let alone Reagent. So I'd start with researching how to do it in JS and then proceed with adapting it for React and replicating it in CLJS+Reagent.
useIntersection
is a hook, and Reagent documents how to use hooks: https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md#hooks
I've come across an issue that I've never dealt with before. I'm trying to use wavesurfer.js in Reagent - it is a javascript object that binds to a dom component which has to be present before it loads, and then provides a waveform on a canvas and various utilities to interact with it. However, I can't figure out how to make it play nicely within react and maintain a reference to it for control and layout purposes. The following code infinitely creates the canvas - what am I missing?
(defn wave-component [id audio]
(with-let [!container (atom nil)
wave (atom nil)
load (fn [] ^js (.load @wave audio))
]
[:div.outer
[:div {:id id
:ref (fn [el] (reset! !container el))
:style {:height "100px" :width "1000px" :background-color "black"}
}]
(when @!container
(reset! wave (wavesurfer/create #js {:container (str "#" id)
:waveColor "violet"
:progressColor "purple"
:backend "MediaElement"
}))
(load)
)
]
)
)
I've got it working in other ways using multiple defns which works fine but then I lose the ability to control playback as I don't have a reference to the object outside of its definition.otherwise you're re-rendering the component when the ref is set, which may change the ref, which re-render the component, etc
I see, thanks you for taking the time to answer. However, this way only the container div renders, not the waveform.