Fork me on GitHub
#reagent
<
2019-10-30
>
dominicm11:10:53

Is it possible to use refs with reagent components (not react interop components).

Roman Liutikov11:10:13

this should work ^{:ref ref} [component]

frankitox15:11:39

Is this about ref forwarding? I tried to run a simple test to try to understand what you guys are talking about but to no avail. Here's what I tried

(defn inner [& args]
  (js/console.log "Args:" args)
  [:div "Hello"])

(defn main []
  (let [ref (react/createRef)]
    (js/setTimeout #(js/console.log "Ref:" ref) 3000)
    ^{:ref ref} [inner]))
When I run it it prints Args: null and Ref: {current: null}. I run it using Reagent version 0.8.1. 😕

Roman Liutikov15:11:38

I have no idea what Reagent does with refs internally

dominicm11:10:56

Ah, I see. Thanks.

frankitox15:11:39

Is this about ref forwarding? I tried to run a simple test to try to understand what you guys are talking about but to no avail. Here's what I tried

(defn inner [& args]
  (js/console.log "Args:" args)
  [:div "Hello"])

(defn main []
  (let [ref (react/createRef)]
    (js/setTimeout #(js/console.log "Ref:" ref) 3000)
    ^{:ref ref} [inner]))
When I run it it prints Args: null and Ref: {current: null}. I run it using Reagent version 0.8.1. 😕