I want to set up a binding, alike (binding [*current-component* c]
; thins binding must take place on all render calls of components that are children of the component that sets it. Any tips?
https://github.com/reagent-project/reagent/issues/520 tips welcome.
There's #re-frame for such specific questions.
Update your re-frame dependency - the :fx
support is fairly recent.
ooh, I didn’t see that channel. Duly noted--I will add that. And thanks--I’ll try that!
I’m trying to stream video using the computer’s built-in camera (if available). I found https://yo-dave.com/2019/05/13/displaying-video-from-a-webcam-using-clojurescript-and-reagent/ using Clojure/Reagent, which was helpful, but I’m assuming perhaps it’s better not to grab the element directly like they did? (I could be wrong--I’m not really well-versed in frontend development--learning!). I see in https://stackoverflow.com/a/53033746, the “React” way of doing this is to create a ref, but so far my attempts at replicating haven’t …. exactly been successful, hah. How would I properly modify the srcObject of a component? Not really sure how refs work, exactly.
> the “React” way of doing this is to create a ref
Yes.
> my attempts at replicating haven’t …. exactly been successful
Can you share the most successful or at least the most succinct attempt?
> How would I properly modify the srcObject of a component?
The srcObject
has no HTML attribute counterpart, so you cannot modify it by modifying Hiccup.
You have to set it in the same exact way as in the linked example. The only difference is in how you get video-element
- in your case it should be via :ref
.
I thought it would be something like
(defn camera-stream [stream]
[:video
{:auto-play true
:ref #(set! (.-srcObject (reagent/current-component)) stream)}]
)
or maybe
(defn camera-stream [stream]
[:video
{:auto-play true
:ref (reagent/current-component)
:srcObject stream}]
but …. did not work. sort of throwing spaghetti on the wallok, nm, i think i may have figured it out, based on errors i have…. looks like maybe
(defn camera-stream [stream]
[:video
{:auto-play true
:ref (fn [com] (set! (.-current .-srcObject com) stream))}])
is the way to go. i think. i have other issues, but, hey, different errors is progress!Yeah, don't use reagent/current-component
when you have other means of accessing the component, like com
.
(.-current .-srcObject com)
doesn't look right. Try replacing it with (.-srcObject com)
.