helix

2021-10-20T02:19:17.203700Z

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

2021-10-20T02:21:50.204100Z

(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")}) }))) ] ))

2021-10-20T13:22:26.205900Z

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 ?

lilactown 2021-10-20T14:50:30.206400Z

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

lilactown 2021-10-20T14:51:26.207500Z

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

lilactown 2021-10-20T14:51:56.208100Z

so I guess my answer is "it depends" 😄

lilactown 2021-10-20T14:52:34.208900Z

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.

lilactown 2021-10-20T14:53:26.209800Z

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.

lilactown 2021-10-20T14:53:54.210400Z

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

2021-10-20T19:18:04.210900Z

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