Fork me on GitHub
#shadow-cljs
<
2018-09-14
>
ghiden05:09:51

anyone know a good example of using create-react-class directly from cljs?

thheller07:09:26

@ghiden there is not much to it. (:require ["create-react-class" :as crc]) (def MyComponent (crc #js {:render (fn [] (this-as this ...))}))

ghiden07:09:57

Thanks. I didn’t know about this-as thing. Now it works.

thheller07:09:05

you can also do wrap this in a proper function if you want

thheller07:09:09

you'd add the same #js {:render ...} as the last arg to the gobj/extend call

thheller07:09:36

but create-react-class is completely fine

ghiden07:09:45

ES6 way? I see

ghiden10:09:16

what would be a reason when I do "release", I get an error from "reagent" saying "js/React is missing". This is :target :npm-module and :runtime :browser. And I get this error from the consumer of this published npm module.

thheller14:09:43

@ghiden globals work differently in node and the way reagent uses the React global won't work there. Didn't reagent switch to a proper require a while ago? are you on an ancient version?

thheller15:09:51

it might work if you do (js/goog.exportSymbol "React" react js/global) when (:require ["react" :as react])

ghiden20:09:23

Yes. I'm using an old version 0.7.0 due to some dependencies restrictions. This doesn't seem to work. But I just tried 0.8.1 and it works.

Logan Powell16:09:00

Since we're talking about using React from shadow-cljs can I ask a naive question? Is pulling in a third-party React component as simple as npm install react-super-cool-component and then (require ["react-super-cool-component" :as rscc])?

thheller16:09:20

yes, 95% of the time

👍 4