Skip to content

Instantly share code, notes, and snippets.

@Chryus
Last active January 2, 2017 19:10
Show Gist options
  • Save Chryus/983f95a6e3b6c5dab22b2c58e1b33b5a to your computer and use it in GitHub Desktop.
Save Chryus/983f95a6e3b6c5dab22b2c58e1b33b5a to your computer and use it in GitHub Desktop.
React avatar with stateless functional components
// 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