You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the first argument is a map, it's used as the element's attributes:
(dom/div {:class"foo"} (dom/p"Hello World"))
Special React options like :key are also supported.
The class attribute may be specified as a collection:
(dom/p {:class ["foo""bar"]} "Hello World")
And the style attribute may be specified as a map:
(dom/p {:style {:color:red}} "Hello World")
If one of the child arguments is a seq, it's expanded out automatically:
(dom/ul
(for [i (range5)]
(dom/li {:key i} i)))
Advanced Usage
Flupot can also be used to define your own wrappers around React
elements or similar libraries (such as react-pixi). You probably
won't need to do this! But just in case...
There are two macros that allow you to do this: defelement-fn and
defelement-macro.
defelement-fn generates a function around an element method, with an
optional attribute transformation function:
This generates a function span that wraps React.DOM.span. The
attribute map is transformed with the cljs.core/clj->js function.
Complementing this is defelement-macro. This generates a macro that
will try to pre-compile as much as possible. If you give the macro the
same name as the function defined by defelement-fn, ClojureScript
will choose the macro when possible, and fall back to the function
otherwise.
This macro has third keyword argument, :attrm, which defines a
function that is applied inside the macro. The flupot.core/clj->js
function mimics cljs.core/clj->js, except that it attempts to
perform as much as the conversion as possible during compile time.