Fork me on GitHub

is it possible to call an exported component from js?


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.

Roman Liutikov10: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

Roman Liutikov10: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

Roman Liutikov10: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

Roman Liutikov10:09:58

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


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


then I get this warning


I can use it like <hello/>.


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


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


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


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


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