Created
November 12, 2015 00:08
-
-
Save paulruescher/b1e605e733f869dfb801 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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