Fork me on GitHub
#reagent
<
2017-03-29
>
seantempesta07:03:15

How do you call a native react component with js props (without clj->js conversion)? When I’m doing this [:> NativeComponent #js {:js-key []}] the props are being passed in as children.

seantempesta07:03:28

looks like (r/adapt-react-class NativeComponent also either does a clj->js conversion or it passes #js props in as children. Huh. Is this a bug?

pesterhazy07:03:02

@seantempesta what's buggy about it?

seantempesta07:03:44

[:> NativeComponent {:a 1}] ; calls NativeComponent with (clj->js {:a 1}) as the props [:> NativeComponent #js {:a 1}] ; calls NativeComponent with nil as props and #js {:a 1} as the children

pesterhazy07:03:33

what behavior would you expect? Reagent props must be a clj map

pesterhazy07:03:17

you could probably avoid the js->clj clj->js roundtrip...

seantempesta07:03:22

I want to call the NativeComponent with a js-obj as the props AND a clj datastructure embedded inside that js-object.

seantempesta07:03:42

NativeComponent isn’t a Reagent component.

pesterhazy07:03:14

but you're using Reagent call-style (`:>` treats the native component like a reagent component)

seantempesta07:03:54

Well, I don’t know how to call a native component within a Reagent component without using :>

pesterhazy07:03:07

hm... you could do [:> (fn [] (js/React.createElement NativeComponent #js {:a 1})] or something like that

pesterhazy07:03:12

or even [:> (js/React.createElement ..)] perhaps?

seantempesta07:03:59

Hmm okay. But shouldn’t [:> NativeComponent #js {:a 1}] work?

pesterhazy07:03:12

I remember seeing adapt-react-class work with #js {:a 1} passed as first argument

pesterhazy07:03:17

but not 100% sure

seantempesta07:03:47

I think I tried that and it did the same behavior: it moved the props to the children.

seantempesta07:03:30

Okay, this is working:

[:> View {:flex            1
                :height          100
                :width           100
                :backgroundColor "red"}
       (r/create-element VirtualizedList #js {:data                  [{:a 1}]
                                              :renderItem            #(r/create-element render-list-element %)
                                              :debug?                true
                                              :disableVirtualization true
                                              :getItem               get
                                              :getItemCount          count
                                              :keyExtractor          #(str (get %1 :db/id))})]

pesterhazy07:03:29

I think that as-element, :> and adapt-react-class can be seen as specializations of create-element

pesterhazy07:03:33

:> is convenient, but if you need an advanced feature (like passing raw JS objects), you need to drop down to create-element

tomaas10:03:48

hi, could anyone explain why the second snippet (`home1`) has the behaviour of making requests in a loop?

pesterhazy10:03:03

render functions should be pure. Move side effects to life-cycle methods or the outer fn in a Form-2 componenet.

tomaas10:03:17

@pesterhazy, as I have it in home definition, right?