Skip to content

Instantly share code, notes, and snippets.

@h4091
Last active December 28, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h4091/f01d7fd57633bb0bb15e480e5d5eb0ac to your computer and use it in GitHub Desktop.
Save h4091/f01d7fd57633bb0bb15e480e5d5eb0ac to your computer and use it in GitHub Desktop.
Test7
<div id="root"></div>
function formatDate(date) {
return date.toLocaleDateString();
}
// avatar component
function Avatar(props) {
return <img className="Avatar"
src={props.user.avatarUrl}
alt={props.user.name} />;
}
function UserInfo(props) {
return (
<div className="UserInfo">
<Avatar user={props.user}/>
<div className="UserInfo-name">
{props.user.name}
</div>
</div>
);
}
function Comment(props) {
return (
<div className="Comment">
<UserInfo user={props.author}/>
<div className="Comment-text">
{props.text}
</div>
<div className="Comment-date">
{formatDate(props.date)}
</div>
</div>
);
}
const comment = {
date: new Date(),
text: 'I hope you enjoy learning React!',
author: {
name: 'Hello Kitty',
avatarUrl: 'http://placekitten.com/g/64/64'
}
};
ReactDOM.render(
<Comment
date={comment.date}
text={comment.text}
author={comment.author} />,
document.getElementById("root")
);
<script src="https://unpkg.com/react/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>

Test7

Learn the fundamentals of React, including simple and class components, state, props, and submitting form data.

Extracting Components

A Pen by 你银子掉了 on CodePen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment