Skip to content

Instantly share code, notes, and snippets.

@Rogdham

Rogdham/App.js Secret

Created February 13, 2019 10:07
Show Gist options
  • Save Rogdham/1a19d9871612bf7145f92cb62138e8fc to your computer and use it in GitHub Desktop.
Save Rogdham/1a19d9871612bf7145f92cb62138e8fc to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class App extends Component {
state = { height: "*loading*" };
componentDidMount() {
this.setState({
height: this.wrapper.offsetHeight
});
}
render() {
return (
<div
ref={obj => {
this.wrapper = obj;
}}
>
My height is {this.state.height}
</div>
);
}
}
export default App;
html, body {
height: 100%;
margin: 0;
}
div {
display: block;
height: 100%;
background-color: red;
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css'
ReactDOM.render(<App />, document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment