Fork me on GitHub
#helix
<
2020-11-17
>
tomc15:11:30

I shared this in the re-frame channel but I thought I'd share it here too, half in case it's useful to anyone else, and half in case someone can point out some flaws: https://gist.github.com/tomconnors/bd3fb275f893a3f16295c2ca93a32b2d - it's an implementation of use-sub for using re-frame subs as react hooks.

jaime20:11:33

Hi, why is ^:native is causing Error: [object Object] is not ISeqable when I'm accessing the (.-button theme) but not when using keyword (:button theme) ... Then why removing ^:native metadata and accessing (.-button theme) works?

value of theme #js {:button #js {:color #6b46c1}, :input #js {:color #4a5568, :borderColor #cbd5e0, :borderWidth 1, :height 40}}

(defnc button [{:keys [on-press data-testid title color]}]
  (let [theme (useTheme)]
    (println "theme " theme)
    ($ rn/Button {:style (.-button theme) <------------ seems like (.-button theme) causes error when adding ^:native
                  :color (.. theme -button -color)
                  :title title
                  :on-press on-press
                  :data-testid data-testid})))

jaime20:11:40

After experimenting a bit, I think the issue is ^:native requires cljs map and not js object... (.-button theme) returns js object, hence the error? The reason (:button theme) works with ^:native metadata is because it returns nil?