1 | import { createElement, Component } from "react";
|
2 | import { render } from "react-dom";
|
3 | import { demo, xyz } from "./unused";
|
4 |
|
5 | import * as styles from "./app.css";
|
6 |
|
7 | demo();
|
8 | xyz();
|
9 |
|
10 | class App extends Component {
|
11 | constructor(props) {
|
12 | super(props);
|
13 |
|
14 | this.state = {
|
15 | stories: [
|
16 | {
|
17 | id: 1,
|
18 | name: "[Webpack] — Smart Loading Assets For Production",
|
19 | url:
|
20 | "https://hackernoon.com/webpack-smart-loading-assets-for-production-3571e0a29c2e"
|
21 | },
|
22 | {
|
23 | id: 2,
|
24 | name: "V8 Engine Overview",
|
25 | url: "https://medium.com/@MQuy90/v8-engine-overview-7c965731ced4"
|
26 | }
|
27 | ]
|
28 | };
|
29 | }
|
30 | render() {
|
31 | const { stories } = this.state;
|
32 |
|
33 | return (
|
34 | <div>
|
35 | <ul>
|
36 | {stories.map((story, index) => (
|
37 | <Story key={index} story={story} onRemove={this.removeStory} />
|
38 | ))}
|
39 | </ul>
|
40 | </div>
|
41 | );
|
42 | }
|
43 | removeStory = story => () => {
|
44 | const { stories } = this.state;
|
45 |
|
46 | const index = stories.findIndex(s => s.id == story.id);
|
47 | stories.splice(index, 1);
|
48 |
|
49 | this.setState(stories);
|
50 | };
|
51 | }
|
52 |
|
53 | class Story extends Component {
|
54 | constructor(props) {
|
55 | super(props);
|
56 |
|
57 | this.state = { likes: Math.ceil(Math.random() * 100) };
|
58 | }
|
59 | render() {
|
60 | const { story, onRemove } = this.props;
|
61 | const { likes } = this.state;
|
62 |
|
63 | return (
|
64 | <li className={styles.notExist}>
|
65 | <button onClick={this.handleClick}>
|
66 | {likes}
|
67 | ❤️
|
68 | </button>
|
69 | <a className={styles.xxx} href={story.url}>
|
70 | {story.name}
|
71 | </a>
|
72 | <button onClick={onRemove(story)}>Remove</button>
|
73 | </li>
|
74 | );
|
75 | }
|
76 | handleClick = () => {
|
77 | this.setState({
|
78 | likes: this.state.likes + 1
|
79 | });
|
80 | };
|
81 | }
|
82 |
|
83 | export function reload() {
|
84 | render(<App />, document.getElementById("root"));
|
85 | }
|
86 |
|
\ | No newline at end of file |