-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathTracedChild.jsx
64 lines (51 loc) · 1.39 KB
/
TracedChild.jsx
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
58
59
60
61
62
63
64
import React, { Component } from 'react';
import { traceLifecycle } from '../src';
class Child extends Component {
state = {};
static staticProperty = 'a static property';
constructor(props, context) {
super(props, context);
props.trace('custom:constructor');
}
// eslint-disable-next-line no-unused-vars
static getDerivedStateFromProps(nextProps, prevState) {
nextProps.trace('custom:getDerivedStateFromProps');
return null;
}
shouldComponentUpdate() {
this.props.trace('custom:shouldComponentUpdate');
return true;
}
render() {
this.props.trace('custom:render');
return (
<div>
<input type='button' data-testid='state-update-button' onClick={this.updateState}/>
<this.props.LifecyclePanel/>
</div>
);
}
componentDidMount() {
this.props.trace('custom:componentDidMount');
}
getSnapshotBeforeUpdate() {
this.props.trace('custom:getSnapshotBeforeUpdate');
return null;
}
componentDidUpdate() {
this.props.trace('custom:componentDidUpdate');
}
componentWillUnmount() {
this.props.trace('custom:componentWillUnmount');
}
updateState = () => {
this.setState(() => {
this.props.trace('custom:setState update fn');
return {};
}, () => {
this.props.trace('custom:setState callback');
});
};
}
const TracedChild = traceLifecycle(Child);
export default TracedChild;