piranha / pump

Pump your REACTive app with fuel
Eclipse Public License 1.0
75 stars 5 forks source link

how to deal with the "Each child in an array should have a unique "key" prop." warning? #10

Open tomconnors opened 10 years ago

tomconnors commented 10 years ago

I see this warning any time I render nested components or vectors of child elements, even if I put a :key or "key" in my property map. If I'm understanding the code correctly, I'm getting the warning because react is looking at the js-object wrapper for the clojure map, trying to find the "key" prop. Of course, the js wrappers for clojurescript data structures have no "key" property, so that lookup fails. I've looked for a way to add a property to the js wrapper for a clojure data structure, but I'm not sure whether that's possible. Have you seen this warning before? How did you deal with it? -Tom

piranha commented 10 years ago

Yeah, I've seen this warning and just did nothing. :) But it's true, it should be dealt with somehow. It could be done when rendering a template, like this:

(tag-fn (aset attrs "key" (:key attrs)) (clj->js (as-content content)))

I'm not sure I like this solution, but it should work at least.

tomconnors commented 10 years ago

Thanks for the response. I haven't gotten this to work yet, so I'm also going to continue doing nothing for now, but if I come up with any other solutions I'll post them back here.