Fork me on GitHub

I’d like to provide the react/View with some default props. What’s the proper way to achieve it?

(def view (r/adapt-react-class react/View))
The function r/adapt-react-class does not allow to provide props


Create a wrapper component.


(defn view
  [& [x & xs]]
  ;; inspecting on the type of `x`.
  ;; if `x` is a map, then it is a prop map
  ;; otherwise it is a child
  ;; xxx
  (let [default-props
        {:auto-capitalize "none"
         :spell-check false
         :auto-correct false}]
    (into [:> react/View (merge default-props x)] xs)))
Reflecting on the type of the first argument seems too much boilerplate


Well, that's just payment for having the ability to have optional props. Quite a few people are unhappy about it because it makes it much harder to work with Hiccup. As an alternative, you can always require the users of your view wrapper to provide it with a props map as the first argument.


There's a similar problem with defn - it supports a lot of optional things different positions. The parsing code is quite a few lines.


Note that there are also r/props and r/children that could be useful here. But using them might also result in unnecessary JS<->CLJS data roundtrips.


Off the topic,

(let [[x & foobar] xs] ,,,)
what’s the typical naming of foobar, h ? t?


Nothing consistent, as far as I'm aware.


If you don't need that xs, I'd name it xs.

👍 1

For the r/children, inside a reagent component, say, form-1, I haven’t returned the hiccups (aka chidlren), what’s the meaning of accessing r/children ?


Not sure what you mean. I haven't checked it, but I think that instead of checking whether there are any arguments and whether the first is a map, you can just use r/props and r/children instead of the props that you pass into the component. So effectively, the passed props will be ignored by your code.


My question was:

(defn sign-in-screen
  ;; the children, here rn/Text has not been returned.
  ;; what's the meaning of r/children?

  [:> rn/Text
   "Sign in"])


r/children is a pure function, with an exception that it accepts one argument and will throw an exception if that argument is not a component.


So the case above is an erroneous usage of the function. And if you replace it with (this-as this (r/children this)), it will just be a no-op.


is #ethereum still active?


If you mean specifically the channel, then its history seems to be an evidence enough. If you mean something CLJS-related, then could you please be more specific?


Does code splitting support some modules being for web pages and other modules being webworkers? (The use case given on is "to load only the code actually required to run a particular logical screen" which taken literally would seem to say all splits must participate in the same SPA, which would exclude web workers and multi-page web applications.) I tried putting :target :webworker into some modules in the compiler options, and did not notice an error message but I have not found webworker bootstrap js in the output.


there is probably a bug in destructuring in cljs, or at least it works differently than in clj

😮 2

(let [{:keys [button_text button-text]} {:button_text "text1" :button-text "text2"}]
  [button_text button-text])
;; => ["text2" "text2"]

(let [{:keys [button_text button-text]} {:button_text "text1" :button-text "text2"}]
  [button_text button-text])
;; => ["text1" "text2"]


It's a known issue. The target language cannot have hyphens and there can be collisions

🙀 2

I don't see it mentioned on "Differences from Clojure" (, nor in Jira either although I might have missed it. Therefore, I hope @U0BBFDED7 will pose a question at By the way, is destructuring necessary to encounter the collision?