Getting clientHeight from a react-reason DOM ref

295 Views Asked by At

I'm accessing a reason-react DOM reference in order to ascertain client height.

Unfortunately clientHeight doesn't seem to be part of the ref API. So this fails:

ref
  -> React.Ref.current
  -> Js.Nullable.toOption
  -> Belt.Option.map(this => {
    React.Ref.clientHeight(this);
});

The value clientHeight can't be found in React.Ref.

Is there a way to extract the height of a component from the ref?

The ref was acquired from a div.

1

There are 1 best solutions below

2
glennsl On BEST ANSWER

Assuming you acquired the ref from either ReactDOMRe.Ref.domRef or ReactDOMRe.Ref.callbackDomRef, you will receive a Dom.element and can use Element.clientHeight from bs-webapi:

open Webapi.Dom;

ref
  -> React.Ref.current
  -> Js.Nullable.toOption
  -> Belt.Option.map(Element.clientHeight);