Last active
December 30, 2015 11:23
-
-
Save johntran/7565719b3c42109045f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from 'react' | |
import usersTable from './usersTable' | |
import fetch from 'fetch' | |
class UserTableContainer extends Component { | |
componentDidMount() { | |
/** | |
* When component is loaded on the page, | |
* get the user list from api and mutate state. | |
*/ | |
fetch('/api/users') | |
.then(response => response.json()) | |
// response = [{name: "John"}, {name: "Mary"}, {name: "Sherry"}] | |
.then(data => this.setState({users: data})) | |
/** | |
* Mutating state is bad, but since we haven't installed | |
* a data dispatcher like Flux/Redux for this example, it is ok. | |
*/ | |
}) | |
.catch(error => console.log('Error: ', error)) | |
} | |
return (<usersTable users={this.state.users} />) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment