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