Skip to content

Instantly share code, notes, and snippets.

@bhb
Created June 14, 2017 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhb/84e55f42c0e17a79b0e60a3ae805c840 to your computer and use it in GitHub Desktop.
Save bhb/84e55f42c0e17a79b0e60a3ae805c840 to your computer and use it in GitHub Desktop.
An example of using `for` vs `map` to apply components
(defn render-cell [{:keys [cellname]}]
(println "cell-name" cellname)
;; Note the key here
[:div {:key cellname}
[:p cellname]])
;; This version works as expected - if I change
;; the second cell, the "println" above only fires for that cell
(defn visible-cells [cells]
[n/view
{}
(for [cell cells]
^{:key (:cellname cell)} [render-cell cell])])
;; This doesn't work - if I change the second cell, the
;; println above fires for all cells
(defn visible-cells2 [cells]
[n/view
{}
(map render-cell cells)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment