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.
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
(defn ^:export button [attrs child]
(Button attrs child))
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
(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 childrenthen 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