Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hiccup and hiccup-seq? #35

Closed
didibus opened this issue Nov 27, 2019 · 4 comments
Closed

Hiccup and hiccup-seq? #35

didibus opened this issue Nov 27, 2019 · 4 comments

Comments

@didibus
Copy link

didibus commented Nov 27, 2019

In the readme, you mention hiccup can't represent sibling elements like:

<p>one</p><p>two</p>

But I'm pretty sure you can do this in Hiccup by wrapping it in a list like:

(list [:p "one"] [:p "two"])
@retrogradeorbit
Copy link
Owner

Yep. That is what hiccup-seq is. A sequence (a list) of hiccup forms.

$ bootleg -d -e '(convert-to "<p>one</p><p>two</p>" :hiccup-seq)'
([:p {} "one"] [:p {} "two"])

@retrogradeorbit
Copy link
Owner

the reverse also works:

$ bootleg -e '(list [:p "one"] [:p "two"])'
<p>one</p><p>two</p>

@retrogradeorbit
Copy link
Owner

Just testing, hiccup does support this sequence:

test2.core=> (use 'hiccup.core)
nil
test2.core=> (html (list [:p "one"] [:p "two"]))
"<p>one</p><p>two</p>"

Will update the documentation to make this clear

@retrogradeorbit
Copy link
Owner

retrogradeorbit commented Nov 29, 2019

As an additional note, reagent proclaims to use hiccup syntax but does not support the list form.

In reagent:

(defn test-page []
  (list [:p "one"] [:p "two"]))

(defn current-page []
  (fn []
    [:div
     [test-page]]))

gives:

Error: Objects are not valid as a React child (found: object with keys {ns, name, fqn, _hash, cljs$lang$protocol_mask$partition0$, cljs$lang$protocol_mask$partition1$}). If you meant to render a collection of children, use an array instead.
    in myreagent.core.test_page (created by myreagent.core.current_page)
    in div (created by myreagent.core.current_page)
    in myreagent.core.current_page 3 react-dom.inc.js:13951:28

Trying a vector:

(defn test-page []
  (vector [:p "one"] [:p "two"]))

(defn current-page []
  (fn []
    [:div
     [test-page]]))

results in

Error: No item [:p "two"] in vector of length 2 2 core.cljs:5383:9

defining a single hiccup form works:

(defn test-page []
  (last (list [:p "one"])) [:p "two"])

(defn current-page []
  (fn []
    [:div
     [test-page]]))

results in

<div><p>two</p></div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants