1. import React from "react";
    2. import ReactDOM from "react-dom";
    3. import "./index.css";
    4. // import App from "./App";
    5. import * as serviceWorker from "./serviceWorker";
    6. import TodoList from "./TodoList";
    7. // function Welcome(props) {
    8. // return <h1>hello,{props.name}</h1>;
    9. // }
    10. // class Welcome extends React.Component {
    11. // render() {
    12. // return <h1>hello,{this.props.name}</h1>;
    13. // }
    14. // }
    15. // const element = <Welcome name="Sara" />;
    16. // function App(){
    17. // return(
    18. // <div>
    19. // <Welcome name="Sara"></Welcome>
    20. // <Welcome name="Sara"></Welcome>
    21. // <Welcome name="Sara"></Welcome>
    22. // </div>
    23. // )
    24. // }
    25. // function formatDate(date) {
    26. // return date.toLocaleDateString();
    27. // }
    28. // const comment = {
    29. // date: new Date(),
    30. // text: "I hope you enjoy learning React!",
    31. // author: {
    32. // name: "Hello Kitty",
    33. // avatarUrl: "https://placekitten.com/g/64/64"
    34. // }
    35. // };
    36. // function Avatar(props) {
    37. // return (
    38. // <img
    39. // className="Avatar"
    40. // src={props.user.avatarUrl}
    41. // alt={props.user.name}
    42. // />
    43. // );
    44. // }
    45. // function UserInfo(props) {
    46. // return (
    47. // <div className="UserInfo">
    48. // <Avatar user={props.user} />
    49. // <div className="UserInfo-name">{props.user.name}</div>
    50. // </div>
    51. // );
    52. // }
    53. // function Comment(props) {
    54. // return (
    55. // <div className="Comment">
    56. // <UserInfo user={props.author} />
    57. // <div className="Comment-text">{props.text}</div>
    58. // <div className="Comment-date">
    59. // {formatDate(props.date)}
    60. // </div>
    61. // </div>
    62. // );
    63. // }
    64. // ReactDOM.render(
    65. // <Comment date={comment.date} text={comment.text} author={comment.author} />,
    66. // document.getElementById("root")
    67. // );
    68. // function Clock(props) {
    69. // return (
    70. // <div>
    71. // <h1>Hello,world!</h1>
    72. // <h2>It is {props.date.toLocaleTimeString()}</h2>
    73. // </div>
    74. // );
    75. // }
    76. // function tick() {
    77. // ReactDOM.render(
    78. // <Clock date={new Date()}></Clock>,
    79. // document.getElementById("root")
    80. // );
    81. // }
    82. // setInterval(tick, 1000);
    83. // function FormattedDate(props) {
    84. // return <h2>It is {props.date.toLocaleTimeString()}</h2>
    85. // }
    86. // class Clock extends React.Component {
    87. // constructor(props) {
    88. // super(props);
    89. // this.state = { date: new Date() };
    90. // }
    91. // componentDidMount() {
    92. // this.timerID = setInterval(() => {
    93. // this.tick();
    94. // }, 1000);
    95. // }
    96. // componentWillUnmount() {
    97. // clearInterval(this.timerID);
    98. // }
    99. // tick() {
    100. // this.setState({
    101. // date: new Date()
    102. // });
    103. // }
    104. // render() {
    105. // return (
    106. // <div>
    107. // <h1>Hello world!</h1>
    108. // <FormattedDate date={this.state.date} />
    109. // </div>
    110. // );
    111. // }
    112. // }
    113. // function App() {
    114. // return (
    115. // <div>
    116. // <Clock />
    117. // <Clock />
    118. // <Clock />
    119. // </div>
    120. // )
    121. // }
    122. // ReactDOM.render(<App />, document.getElementById("root"));
    123. // class Toggle extends React.Component {
    124. // constructor(props) {
    125. // super(props);
    126. // this.state = { isToggleOn: true };
    127. // this.handleClick = this.handleClick.bind(this);
    128. // }
    129. // handleClick() {
    130. // console.log(this)
    131. // this.setState(prevState => ({
    132. // isToggleOn: !prevState.isToggleOn
    133. // }));
    134. // }
    135. // render() {
    136. // return (
    137. // <button onClick={this.handleClick}>
    138. // {this.state.isToggleOn ? "ON" : "OFF"}
    139. // </button>
    140. // );
    141. // }
    142. // }
    143. // ReactDOM.render(<Toggle />, document.getElementById("root"));
    144. // function UserGreeting(props) {
    145. // return <h1>Welcome back!</h1>;
    146. // }
    147. // function GuestGreeting(props) {
    148. // return <h1>Please sign up.</h1>;
    149. // }
    150. // function Greeting(props) {
    151. // const isLoggedIn = props.isLoggedIn;
    152. // if (isLoggedIn) {
    153. // return <UserGreeting />;
    154. // }
    155. // return <GuestGreeting />;
    156. // }
    157. // ReactDOM.render(
    158. // <Greeting isLoggedIn={false} />,
    159. // document.getElementById("root")
    160. // );
    161. // class LoginControl extends React.Component {
    162. // constructor(props) {
    163. // super(props);
    164. // this.handleLoginClick = this.handleLoginClick.bind(this);
    165. // this.handleLogoutClick = this.handleLogoutClick.bind(this);
    166. // this.state = { isLoggedIn: false };
    167. // }
    168. // handleLoginClick() {
    169. // this.setState({ isLoggedIn: true });
    170. // }
    171. // handleLogoutClick() {
    172. // this.setState({ isLoggedIn: false });
    173. // }
    174. // render() {
    175. // const isLoggedIn = this.state.isLoggedIn;
    176. // let button;
    177. // if (isLoggedIn) {
    178. // button = <LogoutButton onClick={this.handleLogoutClick} />;
    179. // } else {
    180. // button = <LoginButton onClick={this.handleLoginClick} />;
    181. // }
    182. // return (
    183. // <div>
    184. // <Greeting isLoggedIn={isLoggedIn} />
    185. // {button}
    186. // </div>
    187. // );
    188. // }
    189. // }
    190. // function UserGreeting(props) {
    191. // return <h1>Welcome back!</h1>;
    192. // }
    193. // function GuestGreeting(props) {
    194. // return <h1>Please sign up.</h1>;
    195. // }
    196. // function Greeting(props) {
    197. // const isLoggedIn = props.isLoggedIn;
    198. // if (isLoggedIn) {
    199. // return <UserGreeting />;
    200. // }
    201. // return <GuestGreeting />;
    202. // }
    203. // function LoginButton(props) {
    204. // return <button onClick={props.onClick}>Login</button>;
    205. // }
    206. // function LogoutButton(props) {
    207. // return <button onClick={props.onClick}>Logout</button>;
    208. // }
    209. // ReactDOM.render(<LoginControl />, document.getElementById("root"));
    210. // function Mailbox(props) {
    211. // const unreadMessages = props.unreadMessages;
    212. // return (
    213. // <div>
    214. // <h1>Hollo!</h1>
    215. // {unreadMessages.length > 0 && (
    216. // <h2>you have {unreadMessages.length}unread messages</h2>
    217. // )}
    218. // </div>
    219. // );
    220. // }
    221. // const messages = ["react", "Re:React", "Re:Re:React"];
    222. // ReactDOM.render(
    223. // <Mailbox unreadMessages={messages} />,
    224. // document.getElementById("root")
    225. // );
    226. // function WarningBanner(props) {
    227. // if (!props.warn) {
    228. // return null;
    229. // }
    230. // return <div className="warning">Warning!</div>;
    231. // }
    232. // class Page extends React.Component {
    233. // constructor(props) {
    234. // super(props);
    235. // this.state = { showWarning: true };
    236. // this.handleToggleClick = this.handleToggleClick.bind(this);
    237. // }
    238. // handleToggleClick() {
    239. // this.setState(prevState => ({
    240. // showWarning: !prevState.showWarning
    241. // }));
    242. // }
    243. // render() {
    244. // return (
    245. // <div>
    246. // <WarningBanner warn={this.state.showWarning} />
    247. // <button onClick={this.handleToggleClick}>
    248. // {this.state.showWarning ? "Hide" : "Show"}
    249. // </button>
    250. // </div>
    251. // );
    252. // }
    253. // }
    254. // ReactDOM.render(<Page />, document.getElementById("root"));
    255. // const numbers = [1, 2, 3, 4, 5];
    256. // const listItems = numbers.map(number => <li>{number}</li>);
    257. // ReactDOM.render(<ul>{listItems}</ul>, document.getElementById("root"));
    258. // function NumberList(props) {
    259. // const numbers = props.numbers;
    260. // const listItems = numbers.map((todo, index) => <li key={index}>{todo}</li>);
    261. // return <ul>{listItems}</ul>;
    262. // }
    263. // const numbers = [6, 7, 8, 9, 10];
    264. // ReactDOM.render(
    265. // <NumberList numbers={numbers} />,
    266. // document.getElementById("root")
    267. // );
    268. // function ListItem(props) {
    269. // return <li>{props.value}</li>;
    270. // }
    271. // function NumberList(props) {
    272. // const numbers = props.numbers;
    273. // const listItems = numbers.map(number => (
    274. // <ListItem key={number.toString()} value={number} />
    275. // ));
    276. // return <ul>{listItems}</ul>;
    277. // }
    278. // const numbers = [1, 2, 3, 4, 5];
    279. // ReactDOM.render(
    280. // <NumberList numbers={numbers} />,
    281. // document.getElementById("root")
    282. // );
    283. // function Blog(props) {
    284. // const sidebar = (
    285. // <ul>
    286. // {props.posts.map(post => (
    287. // <li key={post.id}>{post.title}</li>
    288. // ))}
    289. // </ul>
    290. // );
    291. // const content = props.posts.map(post => (
    292. // <div key={post.id}>
    293. // <h3>{post.title}</h3>
    294. // <p>{post.content}</p>
    295. // </div>
    296. // ));
    297. // return (
    298. // <div>
    299. // {sidebar}
    300. // <hr />
    301. // {content}
    302. // </div>
    303. // );
    304. // }
    305. // const posts = [
    306. // { id: 1, title: "Hello Wrold", content: "Welcome to learning React!" },
    307. // { id: 2, title: "Installation", content: "You can install React from npm." }
    308. // ];
    309. // ReactDOM.render(<Blog posts={posts} />, document.getElementById("root"));
    310. // function ListItem(props) {
    311. // return <li>{props.value}</li>;
    312. // }
    313. // function NumberList(props) {
    314. // const numbers = props.numbers;
    315. // return (
    316. // <ul>
    317. // {numbers.map(number => (
    318. // <ListItem key={number.toString()} value={number} />
    319. // ))}
    320. // </ul>
    321. // );
    322. // }
    323. // const numbers = [1, 2, 3, 4, 5];
    324. // ReactDOM.render(
    325. // <NumberList numbers={numbers} />,
    326. // document.getElementById("root")
    327. // );
    328. // class NameForm extends React.Component {
    329. // constructor(props) {
    330. // super(props);
    331. // this.state = { value: "" };
    332. // this.handleChange = this.handleChange.bind(this);
    333. // this.handleSubmit = this.handleSubmit.bind(this);
    334. // }
    335. // handleChange(event) {
    336. // this.setState({ value: event.target.value });
    337. // }
    338. // handleSubmit(event) {
    339. // this.state.value
    340. // ? alert("A name was submitted: " + this.state.value)
    341. // : alert("name null");
    342. // event.preventDefault();
    343. // }
    344. // render() {
    345. // return (
    346. // <form onSubmit={this.handleSubmit}>
    347. // <label>
    348. // Name:
    349. // <input
    350. // type="text"
    351. // value={this.state.value}
    352. // onChange={this.handleChange}
    353. // />
    354. // </label>
    355. // <input type="submit" value="Submit" />
    356. // </form>
    357. // );
    358. // }
    359. // }
    360. // ReactDOM.render(<NameForm />, document.getElementById("root"));
    361. // class FlavorForm extends React.Component {
    362. // constructor(props) {
    363. // super(props);
    364. // this.state = { value: "coconut" };
    365. // this.handleChange = this.handleChange.bind(this);
    366. // this.handleSubmit = this.handleSubmit.bind(this);
    367. // }
    368. // handleChange(event) {
    369. // this.setState({ value: event.target.value });
    370. // }
    371. // handleSubmit(event) {
    372. // alert("Your favorite flavor is: " + this.state.value);
    373. // event.preventDefault();
    374. // }
    375. // render() {
    376. // return (
    377. // <form onSubmit={this.handleSubmit}>
    378. // <label>
    379. // Pick your favorite flavor:
    380. // <select
    381. // value={this.state.value}
    382. // onChange={this.handleChange}
    383. // >
    384. // <option value="grapefruit">Grapefruit</option>
    385. // <option value="lime">Lime</option>
    386. // <option value="coconut">Coconut</option>
    387. // <option value="mango">Mango</option>
    388. // </select>
    389. // </label>
    390. // <input type="submit" value="Submit" />
    391. // </form>
    392. // );
    393. // }
    394. // }
    395. // ReactDOM.render(<FlavorForm />, document.getElementById("root"));
    396. // class Reservation extends React.Component {
    397. // constructor(props) {
    398. // super(props);
    399. // this.state = {
    400. // isGoing: true,
    401. // numberOfGuests: 2
    402. // };
    403. // this.handleInputChange = this.handleInputChange.bind(this);
    404. // }
    405. // handleInputChange(event) {
    406. // const target = event.target;
    407. // const value =
    408. // target.type === "checkbox" ? target.checked : target.value;
    409. // const name = target.name;
    410. // this.setState({
    411. // [name]: value
    412. // });
    413. // }
    414. // render() {
    415. // return (
    416. // <form>
    417. // <label>
    418. // Is going:
    419. // <input
    420. // name="isGoing"
    421. // type="checkbox"
    422. // checked={this.state.isGoing}
    423. // onChange={this.handleInputChange}
    424. // />
    425. // </label>
    426. // <br />
    427. // <label>
    428. // Number of guests:
    429. // <input
    430. // name="numberOfGuests"
    431. // type="number"
    432. // value={this.state.numberOfGuests}
    433. // onChange={this.handleInputChange}
    434. // />
    435. // </label>
    436. // </form>
    437. // );
    438. // }
    439. // }
    440. // ReactDOM.render(<Reservation />, document.getElementById("root"));
    441. // function BoilingVerdict(props) {
    442. // if (props.celsius >= 100) {
    443. // return <p>The water would boil.</p>;
    444. // }
    445. // return <p>The water would not boil.</p>;
    446. // }
    447. // class Calculator extends React.Component {
    448. // constructor(props) {
    449. // super(props);
    450. // this.handleChange = this.handleChange.bind(this);
    451. // this.state = { temperature: "" };
    452. // }
    453. // handleChange(e) {
    454. // this.setState({ temperature: e.target.value });
    455. // }
    456. // render() {
    457. // const temperature = this.state.temperature;
    458. // return (
    459. // <fieldset>
    460. // <legend>Enter temperature in Celsius:</legend>
    461. // <input value={temperature} onChange={this.handleChange} />
    462. // <BoilingVerdict celsius={parseFloat(temperature)} />
    463. // </fieldset>
    464. // );
    465. // }
    466. // }
    467. // ReactDOM.render(<Calculator />, document.getElementById("root"));
    468. // const scaleNames = {
    469. // c: "Celsius",
    470. // f: "Fahrenheit"
    471. // };
    472. // function toCelsius(fahrenheit) {
    473. // return ((fahrenheit - 32) * 5) / 9;
    474. // }
    475. // function toFahrenheit(celsius) {
    476. // return (celsius * 9) / 5 + 32;
    477. // }
    478. // function tryConvert(temperature, convert) {
    479. // const input = parseFloat(temperature);
    480. // if (Number.isNaN(input)) return "";
    481. // const output = convert(input);
    482. // const rounded = Math.round(output * 1000) / 1000;
    483. // return rounded.toString();
    484. // }
    485. // function BoilingVerdict(props) {
    486. // if (props.celsius >= 100) {
    487. // return <p>The water would boil.</p>;
    488. // }
    489. // return <p>The water would not boil.</p>;
    490. // }
    491. // class TemperatureInput extends React.Component {
    492. // constructor(props) {
    493. // super(props);
    494. // this.handleChange = this.handleChange.bind(this);
    495. // }
    496. // handleChange(e) {
    497. // this.props.onTemperatureChange(e.target.value);
    498. // }
    499. // render() {
    500. // const temperature = this.props.temperature;
    501. // const scale = this.props.scale;
    502. // return (
    503. // <fieldset>
    504. // <legend>Enter temperature in {scaleNames[scale]}:</legend>
    505. // <input value={temperature} onChange={this.handleChange} />
    506. // </fieldset>
    507. // );
    508. // }
    509. // }
    510. // class Calculator extends React.Component {
    511. // constructor(props) {
    512. // super(props);
    513. // this.handleCelsiusChange = this.handleCelsiusChange.bind(this);
    514. // this.handleFahrenheitChange = this.handleFahrenheitChange.bind(this);
    515. // this.state = { temperature: "", scale: "c" };
    516. // }
    517. // handleCelsiusChange(temperature) {
    518. // this.setState({ scale: "c", temperature });
    519. // }
    520. // handleFahrenheitChange(temperature) {
    521. // this.setState({ scale: "f", temperature });
    522. // }
    523. // render() {
    524. // const scale = this.state.scale;
    525. // const temperature = this.state.temperature;
    526. // const celsius =
    527. // scale === "f" ? tryConvert(temperature, toCelsius) : temperature;
    528. // const fahrenheit =
    529. // scale === "c" ? tryConvert(temperature, toFahrenheit) : temperature;
    530. // return (
    531. // <div>
    532. // <TemperatureInput
    533. // scale="c"
    534. // temperature={celsius}
    535. // onTemperatureChange={this.handleCelsiusChange}
    536. // />
    537. // <TemperatureInput
    538. // scale="f"
    539. // temperature={fahrenheit}
    540. // onTemperatureChange={this.handleFahrenheitChange}
    541. // />
    542. // <BoilingVerdict celsius={parseFloat(celsius)} />
    543. // <Button type="primary" icon="search">
    544. // Search
    545. // </Button>
    546. // </div>
    547. // );
    548. // }
    549. // }
    550. // ReactDOM.render(<Calculator />, document.getElementById("root"));
    551. ReactDOM.render(<TodoList />, document.getElementById("root"));
    552. // If you want your app to work offline and load faster, you can change
    553. // unregister() to register() below. Note this comes with some pitfalls.
    554. // Learn more about service workers: https://bit.ly/CRA-PWA
    555. serviceWorker.unregister();