Last active
January 2, 2017 19:10
-
-
Save Chryus/983f95a6e3b6c5dab22b2c58e1b33b5a to your computer and use it in GitHub Desktop.
React avatar with stateless functional components
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
// Example building avatar section with stateless functional components | |
function ProfilePic(props) { | |
return ( | |
<img src={props.imageUrl} style={{width:100, height:100}}/> | |
); | |
} | |
function ProfileName(props) { | |
return ( | |
<div>{props.name}</div> | |
); | |
} | |
function ProfileLink(props) { | |
return ( | |
<a href={'https://www.github.com/' + props.username}> | |
{props.username} | |
</a> | |
); | |
} | |
function Avatar(props) { | |
return ( | |
<div> | |
<ProfilePic imageUrl={props.user.image} /> | |
<ProfileName name={props.user.name} /> | |
<ProfileLink username={props.user.username} /> | |
</div> | |
); | |
} | |
const user_data = { | |
name: 'Chris Haack', | |
username: 'chryus', | |
image: 'https://avatars0.githubusercontent.com/u/5354390?v=3&s=460' | |
} | |
ReactDOM.render( | |
<Avatar user={user_data} />, | |
document.getElementById('avatar') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment