Instantly share code, notes, and snippets.

Embed
What would you like to do?
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