Skip to content

Instantly share code, notes, and snippets.

@DonDebonair
Last active February 27, 2016 15:33
Show Gist options
  • Save DonDebonair/98ec2c2d14c200becd8a to your computer and use it in GitHub Desktop.
Save DonDebonair/98ec2c2d14c200becd8a to your computer and use it in GitHub Desktop.
Generate keys for children in reagent component automatically
(defmacro defcomponent [name attrs & body]
(let [i (.indexOf attrs '&)]
(if (> i -1)
(let [sym (get attrs (inc i))]
`(defn ~name ~attrs
~@(postwalk-replace {sym `(with-idx ~sym)} body)))
`(defn ~name ~attrs
~@body))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment