Skip to content

More advanced Reagent techniques

Mike Thompson edited this page Mar 1, 2016 · 21 revisions

Of Interest:

Small FAQs:

1. How can I use an entity like "nbsp"

If you try to do this:

[:div  "hello" "&nbsp;" "there"]     ;; <--- note: attempt to use an entity

then you will see the string for the entity. Which is not what you want.

Instead you should do this:

  1. Require in goog's string module...
(:require [goog.string :as gstring])
  1. Use it like this ...
 [:div "hello"  (gstring/unescapeEntities "&nbsp;") "there"]

2. How do I get props in component-will-receive-props

Question

So :component-will-receive-props is a function with this signature (fn [this new-argv]) How do I get new props from new-argv parameter. It’s a function.

Answer

reagent.impl.util/extract-props

3. Some Of My Attributes Don't Appear

Question

I want to render a table like:

[:table.table.table-bordered
 [:tbody
  [:tr
   [:th {:colspan "2"} "2"]]
  [:tr
   [:th 1]
   [:th 2]]]]

but, when I inspect the rendered HTML in the browser, there is no colspan property. What have I done wrong?

Answer

https://github.com/reagent-project/reagent/issues/199

4. Using CommonJS modules

Question

I want to use some React components which are packed as CommonJS modules. How do I do it?

Answer

http://stackoverflow.com/a/35734001

Clone this wiki locally