Created
September 6, 2014 14:26
-
-
Save gaearon/ba7eb92b96c13ede7fe9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var Article = React.createClass({ | |
mixins: [createStoreMixin(UserStore)], | |
propTypes: { | |
article: PropTypes.object.isRequired | |
}, | |
getStateFromStores() { | |
return { | |
author: UserStore.get(this.props.article.authorId); | |
} | |
}, | |
render() { | |
var article = this.props.article, | |
author = this.state.author; | |
return ( | |
<div> | |
<UserLink user={author}> | |
<UserAvatar user={author} /> | |
</UserLink> | |
<h1>{article.title}</h1> | |
<p>{article.text}</p> | |
<p>Read more by <UserLink user={author} />.</p> | |
</div> | |
) | |
} | |
}); | |
var UserAvatar = React.createClass({ | |
propTypes: { | |
user: PropTypes.object.isRequired | |
}, | |
render() { | |
var user = this.props.user; | |
return ( | |
<img src={user.thumbnailUrl} /> | |
) | |
} | |
}); | |
var UserLink = React.createClass({ | |
propTypes: { | |
user: PropTypes.object.isRequired | |
}, | |
render() { | |
var user = this.props.user; | |
return ( | |
<Link to='user' params={{ userId: this.props.user.id }}> | |
{this.props.children || user.name} | |
</Link> | |
) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment