Fork me on GitHub
#helix
<
2021-10-20
>
geraldodev02:10:17

Hi folks, is it ok to use ->clj from cljs-bean.core on a helix component to destructure a javascript react hook ?

geraldodev02:10:50

(defnc Origem [] (let [ [is-dragging drag drag-preview] (->clj (useDrag (fn [] #js {:type "BOX" :collect (fn [monitor] ; (.log js/console monitor) #js {:isDragging (gobj/get monitor "isDragging")}) }))) ] ))

geraldodev13:10:26

I know it's a bit off topic, but helix comes with cljs-bean and the point of helix + shadow is consume the libraries without wrappers, so I'm asking, when you interact with js hooks do you use cljs-bean ?

lilactown14:10:30

i typically do not but I don't use a ton of 3rd party libraries rn

lilactown14:10:26

you can destructure arrays, so the only reason you would do this is for cljs-bean's recursive conversion of drag and drag-preview into CLJS-like data. I don't know what those are normally, so I don't know if I would use bean with it or not

lilactown14:10:56

so I guess my answer is "it depends" 😄

lilactown14:10:34

one thing that ->clj is going to do is create a new reference every render. that might break memoization somewhere else, where it expects the reference to be stable.

lilactown14:10:26

in that case, what I would suggest is creating a custom hook use-drag that memoizes the ->clj to happen only when the values returned by useDrag change.

lilactown14:10:54

ultimately every library and case can be different so I don't have an "I always do this" or "I never do this." sorry!

geraldodev19:10:04

@lilactown Thank you, that's the guidance I was looking for.