Created
November 11, 2015 23:34
-
-
Save paulruescher/06f2033416286bb8bccc 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", | |
}, | |
]; | |
// "Smart" notification component | |
const NotificationsContainer = React.createClass({ | |
componentWillMount() { | |
this.setState({ | |
notifications | |
}); | |
}, | |
render() { | |
const Component = this.props.component; | |
return ( | |
<Component | |
notifications={this.state.notifications} | |
/> | |
); | |
}, | |
}); | |
// "Dumb" notification component | |
const Notifications = 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> | |
<NotificationsContainer | |
component={Notifications} | |
/> | |
</div> | |
); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment