-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLv02_PureComponent.js
More file actions
57 lines (51 loc) · 1.18 KB
/
Copy pathLv02_PureComponent.js
File metadata and controls
57 lines (51 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { PureComponent } from 'react';
import { person } from '../constants';
class Foo extends PureComponent {
render() {
console.log('Lv02_PureComponent: Foo render');
return <div>Foo</div>;
}
}
class Bar extends PureComponent {
render() {
const { person, num } = this.props;
console.log(`Lv02_PureComponent: Bar${num} render`);
return (
<div>
Bar{num} {person.info.age}
</div>
);
}
}
class Lee extends PureComponent {
render() {
console.log(`Lv02_PureComponent: Lee${this.props.num} render`);
return <div>Lee</div>;
}
}
export default class Demo2 extends PureComponent {
state = {
count: 0,
};
handleHoo = () => {};
render() {
const { count } = this.state;
return (
<div>
<button
onClick={() => {
this.setState({ count: count + 1 });
}}
>
Click count
</button>
<p>count: {count}</p>
<Foo name={'Richard'} />
<Bar num={1} person={{ info: { age: 18 } }} />
<Bar num={2} person={person} />
<Lee num={1} handle={() => {}} />
<Lee num={2} handle={this.handleLee} />
</div>
);
}
}