weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.66k stars 174 forks source link

Feature request for `[:<>]` #164

Closed agzam closed 4 years ago

agzam commented 4 years ago

Would it be possible to add a feature similar to Re-agent's support for React Fragments. So it is possible to do things like this:

(def content
  [:<>
    [:li "one"]
    [:li "two"]
    [:li "three"]])

(html5 
  [:ul content])

Currently you have to do something like:

(def content
  [[:li "one"] [:li "two"] [:li "three"]])

(html5 
  [:ul (map identity content)])

Which is a bit difficult, now the caller has to know about the structure of sub-component

weavejester commented 4 years ago

You can just return a seq directly:


(def content
  (list
   [:li "one"]
   [:li "two"]
   [:li "three"]))
agzam commented 4 years ago

Thank you James. Somehow trying that didn't occur to me.

mhuebert commented 3 years ago

When targeting react w/ reagent, something like [:<> child1 child2] and (list child1 child2) represent the same DOM elements but they are treated differently by React - the former doesn't require a unique key for each child, whereas the latter does. Supporting :<> on the server (in this lib) would make it easier to write code that works in both environments.

shaunlebron commented 2 years ago

rum can be used to render react-specific hiccups (with :<> fragments) on server side via rum.core/render-html.