Fork me on GitHub
Rupert (All Street)13:08:58

With uix you can usually create a ref then pass it into a component to attach it e.g.

(let[r (uix/ref)]
   (do-something-with r)
  [:div {:ref r} "ABC"]
Would that work for you?

Rupert (All Street)13:08:32

Alternatively :ref attribute on a component can be a callback function that receives the ref. e.g.

[:div {:ref (fn [element] (.-width (.getBoundingClientRect element)))} "ABC"]

Rupert (All Street)13:08:29

The (uix/ref) can also be created in a parent component and passed down to a child

(defn child [r] [:div {:ref r} "ABC"] )
(defn parent[] (let[r (uix/ref)] [child r]))
I've found these two ways of managing refs are usually enough without needing react/forwardsRef

Ben Hammond14:08:59

the Transition component is getting started from within the material-ui Dialog which causes me a bit of confusion about how the Transition and the ref get set up

Rupert (All Street)14:08:23

I'm wondering if you can do something like:

[:> Dialog/default
      {:open @opened
       :TransitionComponent Slide

Rupert (All Street)14:08:11

(i.e. just pass in the class name without any ref required.

Ben Hammond20:08:30

so if I rewrite as

(defn Transition2
  [:> Slide/default {:direction "up" :ref ref}])

(defn AlertDialogSlide
  (let [opened (uix/state false)
        r (uix/ref)]
     [:> Button/default {:variant "outlined"
                         :color "primary"
                         :on-click #(reset! opened true)}
      "Slide in alert dialog"]
     [:> Dialog/default
      {:open @opened
       :TransitionComponent (uix/as-react (Transition2 r)) 
       :on-close #(reset! opened false)
       :aria-labelledby "alert-dialog-slide-title"
       :aria-describedby "alert-dialog-slide-description"}
then I get the load-time error
checkPropTypes.js:21 Warning: Failed prop type: Invalid prop `children` supplied to `ForwardRef`. Expected an element that can hold a ref. Did you accidentally use a plain function component for an element instead? For more information see 
    in ForwardRef (created by ForwardRef)
    in ForwardRef (created by WithStyles(ForwardRef))
    in WithStyles(ForwardRef) (created by uix.checkmate-dialog/AlertDialogSlide)
    in div (created by uix.checkmate-dialog/AlertDialogSlide)
    in uix.checkmate-dialog/AlertDialogSlide
    in uix.checkmate-dialog/AlertDialogSlide (created by )
    in div (created by )
    in ThemeProvider (created by )