Provide stable keys for components in lists

See https://preactjs.com/tutorial/08-keys/
This commit is contained in:
arne 2025-11-21 17:03:50 +01:00
commit 85004ada3f

View file

@ -415,10 +415,11 @@
[:time.date {:datetime (:created_at post)} (first (str/split (:created_at post) "T"))]]] [:time.date {:datetime (:created_at post)} (first (str/split (:created_at post) "T"))]]]
[:section.content {:dangerouslySetInnerHTML (r/unsafe-html (:content post))}] [:section.content {:dangerouslySetInnerHTML (r/unsafe-html (:content post))}]
(when (seq (:media_attachments post)) (when (seq (:media_attachments post))
[:section.attachments (into [:section.attachments]
(map-indexed (fn [idx item] (map (fn [item]
^{:key idx} [attachment {:attachment item}]) (let [key (str "post-" (:id post) "-attachment-" (:id item))]
(:media_attachments post))]) ^{:key key} [attachment {:attachment item}])))
(:media_attachments post)))
[:nav [:nav
[:ul.controls [:ul.controls
[:li.control-element.url [:li.control-element.url
@ -519,8 +520,11 @@
[:section.buttons [:section.buttons
[:button.control-button {:on-click fetch-more-posts! :disabled (boolean (seq loading))} "⇓ Fetch more"] [:button.control-button {:on-click fetch-more-posts! :disabled (boolean (seq loading))} "⇓ Fetch more"]
[:button.control-button {:on-click disconnect-account!} "▤ Disconnect account"]]] [:button.control-button {:on-click disconnect-account!} "▤ Disconnect account"]]]
[:ul.results (map-indexed (fn [idx p] (into [:ul.results]
^{:key idx} [:li.result [post {:post p}]]) displayed-posts)]])) (map (fn [p]
(let [key (str "post-" (:id p))]
^{:key key} [:li.result [post {:post p}]])))
displayed-posts)]))
;; help section ;; help section