Created
June 14, 2017 21:18
-
-
Save bhb/84e55f42c0e17a79b0e60a3ae805c840 to your computer and use it in GitHub Desktop.
An example of using `for` vs `map` to apply components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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