Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var UserList = React.createClass({
render() {
return (
<table>
<thead>
<tr>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
{this.props.users.filter(user => user.enabled).map(user => <UserRow user={user} />)}
</tbody>
</table>
);
}
});
var UserRow = React.createClass({
contextTypes: {
userService: React.PropTypes.object
},
render() {
return (
<tr>
<td>{this.props.user.name}</td>
<td><button onClick={this.disable}>Disable</td>
</tr>
);
},
disable() {
this.context.userService.disable(this.props.userId);
}
});
var UserView = React.createClass({
childContextTypes: {
userStore: React.PropTypes.shape({
disable: React.PropTypes.func
})
},
getInitialState() {
return {
users: []
}
},
getChildContext() {
return {
userStore: {
disable: userId =>
xhr.post(`/api/user/${userId}/disable`)
.then(() => xhr.get(`/api/user`))
.then(users => this.setState({ users }));
}
};
},
render() {
return (
<UserList users={this.state.users} />
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.