Skip to content

Instantly share code, notes, and snippets.

@whtswrng
Last active October 13, 2018 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whtswrng/c9c4e0fc609893784f11432801e0fd8b to your computer and use it in GitHub Desktop.
Save whtswrng/c9c4e0fc609893784f11432801e0fd8b to your computer and use it in GitHub Desktop.
class UserList extends Component {
static propTypes = {
fetchUsers: PropTypes.func.isRequired,
saveUsers: PropTypes.func.isRequired
};
state = {
users: [{name: 'Jim', surname: 'Smith', age: 33}]
};
componentDidMount() {
const users = this.props.fetchUsers();
this.setState({users});
}
render() {
return (
<div>
<UserTable users={this.state.users} onUserChange={(user) => this.updateUser(user)}/>
<button onClick={() => this.saveUsers()}>Save</button>
</div>
);
}
updateUser(user) {
// update user in the state
}
saveUsers(row) {
this.props.saveUsers(this.state.users);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment