Let's say I have a component that takes an element as a prop called customHeader:
const Example = ({ children, customHeader }) => {
...some code
return (
<>
{customHeader ? customHeader : <div>Default Header</div>}
{children}
</>
);
}
Then where I use the Example
component I do the following:
<Example customHeader={<div>blah</div>}>
<div>children</div>
</Example>
So far this is fairly standard stuff and everything is working but the problem I have is that I want to be able to grab the dimensions of the customHeader
element by doing something like customHeader.clientHeight
but that won't work. When I console.log
it I get this object printed out:
{
$$typeof: Symbol(react.element)
key: ".0"
props: {children: 'Blah'}
ref: null
type: "div"
_owner: FiberNode {tag: 0, key: null, stateNode: null, elementType: ƒ, type: ƒ, …}
_store: {validated: false}
}
Is there a way to convert a JSX element that is passed as a prop to an "normal" HTML element so I can read a bunch of information off it?