Skip to content

Instantly share code, notes, and snippets.

@paulruescher
Last active December 7, 2015 20:02
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 paulruescher/77970c5bd3b5c54799a1 to your computer and use it in GitHub Desktop.
Save paulruescher/77970c5bd3b5c54799a1 to your computer and use it in GitHub Desktop.
const Container = React.createClass({
componentDidMount() {
const success = (notifications) => {
this.setState({
notifications: notifications,
});
};
$.ajax({
url: '/notifications',
dataType: 'json',
success: success,
});
},
onMarkAsRead(id) {
// some mark as read logic
},
render() {
const Component = this.props.component;
return (
<Component
notifications={this.state.notifications}
onMarkAsRead={this.onMarkAsRead}
/>
);
},
});
const Presentation = React.createClass({
renderNotification({notification}) {
const { id, date, message } = notification;
return (
<div>
<span>{message} — {date}</span>
<button onClick={this.props.onMarkAsRead.bind(null, id)}>Mark as Read</button>
</div>
);
},
render() {
return <div>{this.props.notifications.map(renderNotification)}</div>;
},
});
const App = React.createClass({
render() {
return <Container
component={Presentation}
/>
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment