You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A `this.props.trace` method gets added to component and can be used to log specific information:
115
+
#### Traced component props: `LifecyclePanel` and `trace`
116
+
117
+
The traced component receives two additional props: `LifecyclePanel` and `trace`. The `LifecyclePanel` prop is a component that can be included in the rendering with `<this.props.LifecyclePanel/>` to display the lifecycle methods of the traced component.
118
+
119
+
```jsx
120
+
render() {
121
+
return (
122
+
..
123
+
<this.props.LifecyclePanel/>
124
+
..
125
+
);
126
+
}
127
+
```
128
+
129
+
The `trace` prop is a function of type `(msg: string) => void` that can be used to log custom messages:
Because we cannot use `this` to refer to the component instance in the static `getDerivedStateFromProps`, `trace` is passed as a third parameter to this method:
137
+
In the constructor we can use `this.props.trace` after the call to `super`, or access `trace` on the `props` parameter:
138
+
139
+
```jsx
140
+
constructor(props) {
141
+
props.trace('before super(props)');
142
+
super(props);
143
+
this.props.trace('after super(props)');
144
+
}
145
+
```
146
+
147
+
In the static `getDerivedStateFromProps` we cannot use `this` to refer to the component instance, but we can access `trace` on the `nextProps` parameter:
0 commit comments