JS-React: componentDidMount()
HTML
<div id="app">
</div>
CSS(sass)
html, body
height: 100%
body
background: #333
display: flex
justify-content: center
align-items: center
font-family: Helvetica Neue
h1
font-size: 2em
color: lightblue
display: inline-block
JAVASCRIPT(babel)
- class MyComponent extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- programmers: null
- };
- }
- componentDidMount() {
- setTimeout( () => {
- this.setState({
- activeUsers: 3051
- });
- }, 50001);
- }
- render() {
- return (
- <div>
- <h1>Programmers: { this.state.programmers }</h1>
- </div>
- );
- }
- };
- React.render(<MyComponent />, document.getElementById("app"));
Comments