index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. import routes from "./config/routes";
  9. /* React components should be:
  10. Focused
  11. Independent
  12. Reusable
  13. Small
  14. Testable
  15. */
  16. let ProfilePic = React.createClass({
  17. render: function () {
  18. return (
  19. <img src={this.props.imageUrl} style={{ height: 100, width: 100 }} />
  20. );
  21. }
  22. });
  23. let Link = React.createClass({
  24. changeURL() {
  25. console.log(this.props.href);
  26. window.location.replace(this.props.href);
  27. },
  28. render() {
  29. return (
  30. <span
  31. style={ { color: "blue", cursor: "pointer" } }
  32. onClick={this.changeURL}>
  33. {this.props.children}
  34. </span>
  35. );
  36. }
  37. });
  38. let ProfileLink = React.createClass({
  39. render: function () {
  40. return (
  41. <div>
  42. <Link href={"https://github.com/" + this.props.username}>{this.props.username}</Link>
  43. </div>
  44. );
  45. }
  46. });
  47. let ProfileName = React.createClass({
  48. render: function () {
  49. return (
  50. <div>{this.props.name}</div>
  51. );
  52. }
  53. });
  54. let Avatar = React.createClass({
  55. render: function () {
  56. const user = this.props.user;
  57. return (
  58. <div>
  59. <ProfilePic imageUrl={user.image} />
  60. <ProfileName name={user.name} />
  61. <ProfileLink username={user.username} />
  62. </div>
  63. );
  64. }
  65. });
  66. ReactDOM.render(
  67. routes,
  68. document.getElementById("app")
  69. );