Fork me on GitHub
#reagent
<
2021-09-10
>
Ryan18:09:00

Hey all, I'm getting a warning about not having a :key prop in a list, but I put a :key prop in a div iterated over by an map-indexed... what could I be missing?

p-himik18:09:16

Can you provide the code?

Ryan19:09:47

I'm even getting it when the sequence has a :key

lilactown19:09:24

each element inside the sequence needs a unique key

manutter5120:09:38

@rdonahue Are you putting your key in the right place?

;; This one works
[:div.item-bar-list
 (for [item items]
   ^{:key react-key}
   [item-row item])]

;; This one does NOT work
[:div.item-bar-list
 (for [item items]
   [item-row {:key react-key} item])]

Ryan20:09:34

My code looks like this:

(defn person-list-phone []
  (let [_ nil]
    [:<>
     [:div.patient-list [:h1 "Patients"]
      [person-list-filters]
      (map-indexed person-list-iterator (person-list/filter-people))
      ]]))
then a fn that conj's the index back into the map
(defn person-list-iterator [index person]
  (let [p (nth person 1)
        p2 (conj p {:index index})]
    (person-list-item-phone p2)
    ))
Then finally the template for the item
(defn person-list-item-phone [p] etc.
I'm assuming I need to annotate the iterator?

Ryan20:09:28

yup its in wrong place