Search code examples
clojurereactjsclojurescripthiccupom

How to use Hickory with Clojurescript (OM/Reagent)?


In my Reagent project, I'm parsing HTML with Hickory and rendering a Hiccup page. The hiccup is rendered. But when I change the page (!reset my view atom), React.js goes crazy because Hickory has generated:

[:div (as-hiccup (parse "<h1>HELLO WORLD!</h1>"))]

=> ([:html {} [:head {}] [:body {} [:h1 {} HELLO WORLD!]]])

As you can see, it has generated <html> <head> <body> tags which I think is causing Reactjs to blow up because my view already have those tags. Ideally, I want it to only generate [:h1 {} HELLO WORLD!]


Solution

  • (map as-hiccup (parse-fragment "<h1>HELLO WORLD!</h1>"))

    generates [:h1 "HELLO WORLD!"]