Skip to content

Instantly share code, notes, and snippets.

@paulruescher
Created November 12, 2015 00:08
Show Gist options
  • Save paulruescher/b1e605e733f869dfb801 to your computer and use it in GitHub Desktop.
Save paulruescher/b1e605e733f869dfb801 to your computer and use it in GitHub Desktop.
const notifications = [
{
date: "Nov 10, 2015 8:00:00",
message: "Tagged in a photo",
},
{
date: "Nov 10, 2015 9:00:00",
message: "Mentioned in a post",
},
];
// Higher-Order Component
const NotificationsContainer = function(Component) {
return React.createClass({
componentWillMount() {
this.setState({
notifications
});
},
render() {
return (
<Component
notifications={this.state.notifications}
/>
);
},
});
}
// "Dumb" notification component
const Notifications = NotificationsContainer(React.createClass({
render() {
return (
<div>
{this.props.notifications.map(notification => {
return (
<div>
<span>{notification.message}</span>
<span>{notification.date}</span>
</div>
);
})}
</div>
);
},
});
// useage
const App = React.createClass({
render() {
return (
<div>
<Notifications />
</div>
);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment