[Reagent] Rendering HTML string in a component?

754 views
Skip to first unread message

Ravindra Jaju

unread,
Jul 14, 2014, 8:44:34 AM7/14/14
to clojur...@googlegroups.com
I'm creating a component to display some content I'm pulling from elsewhere.

The content (from a DB) has some simple HTML snippets that I wish to use while creating a reagent component. I'm unable to figure out how to stick it in. Is it even possible entirely within reagent. Would I need to somehow parse it and create a hiccup-like structure out it?

Another dependency I have in my project is on dommy - in case anyone has any ideas on how I could use it. (I found out html->nodes and was wondering if there's an easy path from there on!)

Regards,
Ravindra

Ivan L

unread,
Jul 14, 2014, 11:05:25 AM7/14/14
to clojur...@googlegroups.com
I'm learning it as well, but my guess is this is probably best done via some third party js to inject it after component mounting. If you're not familiar with react lifecycle events you should read up on that now, basically they are hooks you can use to alter the real dom after it has been rendered. react docs has some info of course, and the reagent long intro has some examples with it in their site extended intro as well as their examples source folder on github.

Ravindra Jaju

unread,
Jul 20, 2014, 7:43:03 AM7/20/14
to clojur...@googlegroups.com
Thanks Ivan.

I felt doing it the way you suggested would somehow defeat the purpose of using reagent in the first place.
I attempted a few approaches, including trying out hickory[1] to convert my HTML fragment into clojure structures.

I ran into issues very specific to my use-case then. I finally had no option but to hook into the React lifecycle and set my HTML.
This works - and along the way, I think I understood Reagent a bit better too! :)

Thanks,
Ravindra



On Mon, Jul 14, 2014 at 8:35 PM, Ivan L <ivan.l...@gmail.com> wrote:
I'm learning it as well, but my guess is this is probably best done via some third party js to inject it after component mounting.  If you're not familiar with react lifecycle events you should read up on that now, basically they are hooks you can use to alter the real dom after it has been rendered.  react docs has some info of course, and the reagent long intro has some examples with it in their site extended intro as well as their examples source folder on github.

--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply all
Reply to author
Forward
0 new messages