Fork me on GitHub
#reagent
<
2018-02-08
>
burke21:02:08

Is there a standard way to use adapt-react-class on many components?

(def Card (reagent/adapt-react-class js/MaterialUI.Card))
(def CardActions (reagent/adapt-react-class js/MaterialUI.CardActions))
(def CardContent (reagent/adapt-react-class js/MaterialUI.CardContent))
I tried to define a macro where I can say (load-material-ui-component Button) and it will expand to Code (def Button (reagent/adapt-react-class js/MaterialUI.Button)) Can you see if there is an error in my macro definition or is this just not possible with macros at compile time in cljs?
(defmacro load-material-ui-component
  [component-name]
  `(def ~(symbol component-name)
     (reagent/adapt-react-class ~(symbol (str "js/MaterialUI." component-name)))))

mikerod21:02:39

The macro approach should be fine. I’ve had somewhat similar macros for the same idea.

mikerod21:02:53

As long as you define your macro correctly and in a clj/cljc ns and include it

mikerod21:02:15

I’m not sure what specific issues you are getting with trying that

burke10:02:42

Thanks for your answer. I defined that macro in a cljs file and did some other mistakes.. fixed that, now its working 😁

justinlee21:02:39

I can’t help you with your macro, but apparently you can directly write [:> js/MaterialUI.CardActions]