User.js

From Bistre Baboon, 4 Weeks ago, written in JavaScript, viewed 19 times.
URL http://codebin.org/view/5b6c8923 Embed
Download Paste or View Raw
  1. import React, { Component } from 'react';
  2.  
  3. export default class Users extends Component {
  4.   constructor(props){
  5.     console.log('constructor');
  6.     super(props);
  7.     this.state = {users: []};
  8.   }
  9.  
  10.   ComponentWillMount(){
  11.     console.log('component will mount');
  12.   }
  13.  
  14.   ComponentDidMount(){
  15.     console.log('component did mount');
  16.     fetch('/users')
  17.       .then(res => res.json())
  18.       .then(users => this.setState({ users }))
  19.   }
  20.  
  21.   render() {
  22.     return (
  23.       <div>
  24.         <h1>Users:</h1>
  25.         <ul>
  26.           {this.state.users.map(user =>
  27.             <li key={user.id}>{user.username}</li>
  28.           )}
  29.         </ul>
  30.       </div>
  31.     );
  32.   }
  33. }
  34.  

Reply to "User.js"

Here you can reply to the paste above