Fork me on GitHub
#rum
<
2018-09-17
>
ghiden10:09:08

is it possible to call an exported component from js?

ghiden10:09:54

I'm using shadow-cljs to create a npm module and trying to use it from a js app but I can't get a proper react component.

roman01la10:09:48

say you have component Button and it should be called like this in cljs (Button attrs child) for JS you have to export a function that does this

roman01la10:09:34

(defn ^:export button [attrs child]
  (Button attrs child))

Alex Miller (Clojure team)12:09:33

I think in general you can just use -A and ignore the rest most of the time

roman01la10:09:33

now if Button expects attrs as Clojure’s hash map, you have to js->clj attrs that comes from JS, because most likely it’s going to be JS Object type

roman01la10:09:58

(defn ^:export button [attrs child]
  (Button (js->clj attrs) child))

mattly16:09:31

you might also want to do

(defn ^:export button [attrs & children]
  (apply Button (js->clj attrs children))
since it seems the common idiom with JS react is to accept multiple children

ghiden19:09:45

then I get this warning

ghiden19:09:12

I can use it like <hello/>.

ghiden19:09:46

very cumbersome but if I do this const Hello = hello and <Hello/>, then it works.

ghiden19:09:08

I guess there is no easy way to use rum in js 😢

ghiden19:09:37

Thank you guys but if someone knows how to, please let me know.

ghiden19:09:38

I could do import { hello as Hello } from 'hello-lib' but still not so nice

ghiden20:09:19

oh, yes, this one works by switching the names in cljs