Home > front end >  How to get the DOM element of an `observer` wrapped component?
How to get the DOM element of an `observer` wrapped component?

Time:04-12

I have defined my JSX components like this:

const ComponentA = observer(({state}) => {return <div></div>})

I am using observer from mobx: https://mobx.js.org/react-integration.html

I need to see what the rendered height is of the div by using the browser API for the DOM node. It will differ based on the contents it contains.

How do I do that?

CodePudding user response:

I'm sorry, I don't really understand what you're trying to get at. Perhaps this will help?

const divRef = useRef();

useEffect(() => {
  console.log(divRef.current.clientHeight);
}, []);

return <div ref={divRef}></div>
  • Related