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)
  1.  class MyComponent extends React.Component {
  2.   constructor(props) {
  3.     super(props);
  4.     this.state = {
  5.       programmers: null
  6.     };
  7.   }
  8.   componentDidMount() {
  9.     setTimeout( () => {
  10.       this.setState({
  11.         activeUsers: 3051
  12.       });
  13.     }, 50001);
  14.   }
  15.   render() {
  16.     return (
  17.       <div>
  18.         <h1>Programmers: { this.state.programmers }</h1>
  19.       </div>
  20.     );
  21.   }
  22. };
  23. React.render(<MyComponent />, document.getElementById("app"));


Comments

Popular posts from this blog

Tech Duos For Web Development

CIFAR-10 Dataset Classification Using Convolutional Neural Networks (CNNs) With PyTorch

Long-short-term-memory (LSTM) Word Prediction With PyTorch