index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const USER_DATA = {
  2. name: "Tyler McGinnis",
  3. username: "tylermcginnis",
  4. image: "https://avatars0.githubusercontent.com/u/2933430?v=3&s=460"
  5. };
  6. let React = require("react");
  7. let ReactDOM = require("react-dom");
  8. /* React components should be:
  9. Focused
  10. Independent
  11. Reusable
  12. Small
  13. Testable
  14. */
  15. let ProfilePic = React.createClass({
  16. render: function () {
  17. return (
  18. <img src={this.props.imageUrl} style={{ height: 100, width: 100 }} />
  19. );
  20. }
  21. });
  22. let ProfileLink = React.createClass({
  23. render: function () {
  24. return (
  25. <div>
  26. <a href={"https://github.com/" + this.props.username}>{this.props.username}</a>
  27. </div>
  28. );
  29. }
  30. });
  31. let ProfileName = React.createClass({
  32. render: function () {
  33. return (
  34. <div>{this.props.name}</div>
  35. );
  36. }
  37. });
  38. let Avatar = React.createClass({
  39. render: function () {
  40. const user = this.props.user;
  41. return (
  42. <div>
  43. <ProfilePic imageUrl={user.image} />
  44. <ProfileLink username={user.username} />
  45. <ProfileName name={user.name} />
  46. </div>
  47. );
  48. }
  49. });
  50. ReactDOM.render(
  51. <Avatar user={USER_DATA} />,
  52. document.getElementById("app")
  53. );