class Test extends Component {
constructor(props) {
super(props);
this.state = {};
}
componentDidMount() {
window.addEventListener("resize", this.handleResize);
}
handleResize = () => {
// ref
console.log(this.mainBox.clientWidth);
// jQuery
console.log($(".mainBox").width());
};
render() {
return (
<div className="mainBox" ref={(ref) => (this.mainBox = ref)}>
test
</div>
);
}
}
module.exports = Test;