Fork me on GitHub
#reagent
<
2016-09-02
>
andre08:09:01

it shows that all react components rerender every time

pesterhazy09:09:54

reagent manages updates by marking components as dirty manually

pesterhazy09:09:59

in a way it circumvents the two official ways of updating components provided by react (state, props)

pesterhazy09:09:11

I wouldn't be surprised if this confused tools

pesterhazy09:09:31

you can verify if components re-render by adding logging to the render method

lwhorton15:09:19

hmm, can someone point out what I’m doing wrong here in trying to “pass-through” reagent components?

(defn foo [props]
  [:div
   (:val props)])

(defn child [props]
  (into [:ul]
        (map (fn [x]
               [:li
                [(:renderer props) x]])
                (:source props))))

(defn parent []
  [child {:source [{:val "a"} {:val "b"}]
          :renderer foo}])

lwhorton15:09:06

I would imagine that given the above ^, parent would ultimately spit out an ul with two lis. Can you hand-down the renderer function in this way? I dont see any reason why not...

lwhorton15:09:47

the issue I’m getting is that foo is invoked incorrectly. It is invoked twice, where props is always null the first time (for some reason), even if I confirm that inside the mapped fn, x is what you would expect: {:val “a”}. The second time it’s invoked, the correct props {:val “a”} are handed in, and the returned data structure is the correct hiccup, but the final output reagent creates is the result of the first invocation, when props was null. Any ideas why this would happen?

lwhorton16:09:02

I’ve also tried making it a dynamic list as opposed to static hiccup, but the issue still arises:

(defn child [props]
  [:ul
   (for [x (:source props)]
     [:li
      [(:renderer props) x]])])

martinklepsch16:09:46

Have you tried:

(defn child [props]
 (into
   [:ul]
   (for [x (:source props)]
     [:li
      [(:renderer props) x]])))

lwhorton16:09:16

ah that’s a good thought - as if maybe the for was never realized. alas, still the same issue @martinklepsch

lwhorton16:09:36

hah, it’s a pebkac 😕

lwhorton16:09:59

making changes to the wrong component expecting data to flow with the above issue :$

johanatan22:09:48

Hi, what is the proper way to put a :key on a (fn [] ...) component? (The usual ^{:key "blah"} prefix isn't working).