Fork me on GitHub
#reagent
<
2019-11-26
>
aisamu13:11:56

Could someone give me some pointers to what's happening under the hood? I can't seem to explain why: a) There are renders where the props are identical (per =) b) Wrapping it with a fn and a create-class "solves" it

(defn reagent-component [...]
  (. js/console log "...") ...)

;; 5 reagent-component calls, then 2 with identical props (per =) 
(def ^:export Component-1
  (r/reactify-component reagent-component))

;; Same 5 reagent-component calls, then 2 with identical props (per =)
(def ^:export Component-2
  (r/reactify-component (r/create-class
                         {:reagent-render cards})))

;; 5 reagent-component calls, (expected)
(def ^:export Component-3
  (r/reactify-component (fn []
                          (r/create-class
                           {:reagent-render cards}))))
Is the extra fn somewhow doing the equality check beforehand and not calling the render function? Why would that be different, since there's no other lifecycle method or wrapping render call in place? And should I be worried (and wrap all my components)?

frozar23:11:01

Hello, I'm working on a textarea component generated by reagent. This component appears after a double click and I'm struggling to understand how to put the cursor of this textarea at the end of it. Do you know how I can set the position of the cursor in this texte area please?

jbrown23:11:34

I've used (.setSelectionRange textarea-dom-node selection-start selection-end) in component-did-mount

frozar23:11:58

Thank you for the answer, it works for me 🙂 Also, to get the textarea-dom-node as I name my event e I get it with (.-target e) . Do you use something else to ge the textarea-dom-node ?

jbrown23:11:21

Well for my case, the user clicks on a div, then the div is replaced with a textarea after the click, so in the :on-click event in the div (.-target e) would be the div not the textarea. So we use (r/dom-node this) in component-did-mount of the textarea component to get the textarea dom node.

jbrown23:11:11

but for you, if the click event is on the textarea (.-target e) will work

frozar23:11:36

Thank you very much for the explanation ^^

🙂 4