This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-13
Channels
- # announcements (2)
- # babashka (2)
- # beginners (112)
- # calva (29)
- # cider (33)
- # clj-kondo (41)
- # cljdoc (10)
- # cljs-dev (2)
- # clojure (72)
- # clojure-berlin (3)
- # clojure-europe (10)
- # clojure-italy (6)
- # clojure-nl (15)
- # clojure-spec (5)
- # clojure-uk (40)
- # clojurescript (1)
- # clr (6)
- # community-development (6)
- # core-async (21)
- # cursive (42)
- # datascript (12)
- # duct (6)
- # flambo (1)
- # fulcro (50)
- # jobs (1)
- # leiningen (3)
- # off-topic (16)
- # re-frame (6)
- # reagent (23)
- # reitit (7)
- # ring-swagger (14)
- # shadow-cljs (35)
- # tools-deps (39)
- # vim (12)
Cool thanks @lilactown
React uses the key to determine whether it can just reorder the DOM rather than re-create the node afresh.
Thanks @dominicm! I started suspecting yesterday that is the cause of my perf problems.
We have something like this, and almost all of those components are defined using (into [:div] (children this))
(defn product-list
[products]
[window
[view
[title "Selected products" @(subscribe [:sel-products])]
[table
[table-header
[table-row
[table-cell ""]
[table-cell "Name"]
[table-cell "Price"]]]
[table-body
(for [prod (subscribe [:products])]
^{:key prod}
[table-row
[table-cell [checkbox {:checked (:selected prod)}]]
[table-cell (:name prod)]
[table-cell (:price prod)]])]]]
[app-footer]])
Every time the subscribe to :sel-products
changes, the whole product list is re-rendered
You probably want to get the id of the product really, or the name if that's unique.
We are actually using (keep-indexed)
and passing i
as key. That list of things doesn’t grow or shrink.
The funny thing is that if I just move [title "Selected Products" @(subscribe [:sel-products])]
to a separate component the problem goes away
What I understand is that deref
is triggering a [product-list]
re-render and reagent for some reason considers that all of the other components inside it should re-render
I don’t think there is something wrong with reagent or React, or even re-frame, I think it has something to do with how I’m defining those components -> (into [:div.class] (children this))