Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is :<> in reagent hiccup?

Tags:

clojure

hiccup

I don't understand the tag ":<>" in the following code clojure re-frame todomvc

(defn todo-app
  []
  [:<>
   [:section#todoapp
    [task-entry]
    (when (seq @(subscribe [:todos]))
      [task-list])
    [footer-controls]]
   [:footer#info
    [:p "Double-click to edit a todo"]]])

Can anyone help me on this?

like image 982
Jack Liu Shurui Avatar asked Oct 03 '20 07:10

Jack Liu Shurui


2 Answers

That is creating a React Fragment:

https://reactjs.org/docs/fragments.html

like image 148
Michiel Borkent Avatar answered Oct 20 '22 09:10

Michiel Borkent


Adding a bit more detail to the previous answer, the fragment gets spliced into a surrounding list instead of creating a child element. In this way, it is similar to the unquoted-splicing operator in Clojure ~@ compared to the regular unquote operator ~. An example:

(defn middle-seq       [] [    :d :e :f])
(defn middle-seq-frag  [] [:<> :d :e :f])

When used to create a Reagent component, we see the difference:

[:a :b :c (middle-seq)      :g :h :i]    ;=> [:a :b :c [:d :e :f] :g :h :i]
[:a :b :c (middle-seq-frag) :g :h :i]    ;=> [:a :b :c  :d :e :f  :g :h :i]

Otherwise, you would have to restructure the input and use concat:

(vec
  (concat
    [:a :b :c]
    (middle-seq) 
    [:g :h :i] ))          ;=> [:a :b :c :d :e :f :g :h :i]
like image 34
Alan Thompson Avatar answered Oct 20 '22 09:10

Alan Thompson