Fork me on GitHub
#helix
<
2023-02-25
>
hifumi12309:02:03

Is there a downside to omitting ^:native when symbols correspond directly to JS components in an ES module? For instance

(require '["@mui/material/Button" :default Button])

(defnc some-component []
  ;; note no ^:native provided
  ($ Button "Hello"))
This seems to work, but I’m wondering if that is a happy accident or it is okay to do this

lilactown18:02:08

I would recommend not using ^:native metadata

lilactown18:02:19

what $ does normally is translates your props map literally. so if you wrote

($ Button {:onClick #(js/alert "hi")} "Hello")
it would literally create a call like
(react/createElement Button #js {:onClick #(js/alert "hi")} "Hello")
this is good, because you can look at the documentation of material UI, see it takes an onClick prop, and write :onClick in your code

lilactown18:02:40

marking it as ^:native will automatically change kebab-case to camelCase for you, as well as translate DOM props like :class to :className and :style will be transformed into a JS object from CLJS data

lilactown19:02:50

IMO this was a mistake to build into $. it's wrong half the time, because sometimes you want the kebab-case transformation but you don't want :style, or you do want transformation from clj->js in some other prop but it doesn't do that for you so you have to remember which props it does automatically and which do not