I'm working on react project and in this project my colleagues and I are using Material UI, for some reason I wanna access to DOM node of another component that wrapped by a HOC. I used react ref for this. but I just get the withStyle object, see below:
This is my TableHead:
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import { TableHead as MaterialTableHead, TableRow } from '@material-ui/core';
import TableCell from './TableCell';
const TableHead = ({ classes, head, ...rest }) => (
<MaterialTableHead {...rest}>
<TableRow>
{head.map(item => (
<TableCell key={item.key} className={classes.headCell} style={{ width: item.width }}>
{item.title}
</TableCell>
))}
</TableRow>
</MaterialTableHead>
);
TableHead.propTypes = {
classes: PropTypes.object.isRequired,
head: PropTypes.arrayOf(PropTypes.shape({
key: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
width: PropTypes.string,
render: PropTypes.func,
})).isRequired,
};
TableHead.defaultProps = {};
const styles = () => ({
headCell: {
fontSize: '18px',
color: '#0c1d38',
},
});
export default withStyles(styles, { withTheme: true })(TableHead);
And in the Table component I wanna calculate height of TableHead component, so I use below code:
<TableHead ref={(header) => { this.header = header; }} head={head} />
and inside of componentDidMount of Table component I console.log(this.header) and just see below:
I seek in the web and find some GitHub issues pages and try innerRef instead of ref but it doesn't help me.
How I can access to DOM node to calculate its height?