-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
50 lines (39 loc) · 965 Bytes
/
test.js
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
import React, { PureComponent } from 'react';
import { render } from 'react-dom';
class App extends PureComponent {
constructor (props) {
super(props);
this.handleIncrement = this.handleIncrement.bind(this);
this.state = {
myObj: {
number: 0
}
};
}
handleIncrement () {
const { myObj } = this.state;
myObj.number++;
// To prove this handle is actually being called
console.log('Incrementing myObj', myObj);
this.setState({
myObj
});
}
render() {
const { myObj } = this.state;
const styles = {
fontFamily: 'sans-serif',
textAlign: 'center',
};
return (
<div style={styles}>
<SubComponent obj={myObj} />
<button onClick={this.handleIncrement}>Increment</button>
</div>
);
}
}
const SubComponent = ({ obj }) => (
<p>Value: {obj.number}</p>
);
render(<App />, document.getElementById('root'));