App.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import PropTypes from "prop-types";
  2. import React, { Component } from "react";
  3. import logo from "./logo.svg";
  4. import "./App.css";
  5. const appName = "MasterControlProgram";
  6. const titleName = "heading";
  7. class Link extends Component {
  8. render() {
  9. return this.props.hide
  10. ? null
  11. : <a href={this.props.address}>Click</a>;
  12. }
  13. }
  14. Link.propTypes = {
  15. address: PropTypes.string,
  16. hide: PropTypes.bool,
  17. };
  18. const Title = ({ text }) => <div>{text}</div>;
  19. Title.propTypes = {
  20. text: PropTypes.string,
  21. };
  22. class App extends Component {
  23. state = {
  24. input: "",
  25. mainColor: "blue",
  26. on: false,
  27. lifeCycle: "",
  28. };
  29. componentDidMount() {
  30. this.setState({ lifeCycle: "componentDidMount" })
  31. }
  32. componentWillReceiveProps() {
  33. this.setState({ lifeCycle: "componentWillReceiveProps" })
  34. }
  35. handleStrings(s) {
  36. return s === "Hello, world";
  37. }
  38. render() {
  39. return (
  40. <div className="App">
  41. <header className="App-header">
  42. <img src={logo} className="App-logo" alt="logo" />
  43. <h1 className="App-title">Welcome to React</h1>
  44. <h3 className={this.state.mainColor}>Everyone is welcome!</h3>
  45. </header>
  46. <Title text="Some title" />
  47. <p className="App-intro">
  48. To get started, edit <code>src/App.js</code> and save to reload.
  49. </p>
  50. <ul className="tyler">
  51. <li>First</li>
  52. <li>Second</li>
  53. <li>Third</li>
  54. </ul>
  55. <p className="button-state">{this.state.on ? "Yes!" : "No!"}</p>
  56. <button onClick={() => this.setState({ on: true })}>Click</button>
  57. <h2>{this.state.input}</h2>
  58. <input type="text" onChange={(e) => this.setState({ input: e.currentTarget.value })} />
  59. <p className="lifeCycle">{this.state.lifeCycle}</p>
  60. </div>
  61. );
  62. }
  63. }
  64. App.displayName = appName;
  65. Title.displayName = titleName;
  66. export { App, Link, appName, titleName };