Skip to content

Commit b397195

Browse files
committed
Hoist static non-react properties
1 parent 6827ede commit b397195

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"webpack-dev-server": "^3.1.4"
7878
},
7979
"dependencies": {
80+
"hoist-non-react-statics": "^2.5.0",
8081
"prop-types": "^15.6.1",
8182
"react-redux": "^5.0.7",
8283
"redux": "^4.0.0",

src/traceLifecycle.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from 'react';
2+
import hoistStatics from 'hoist-non-react-statics';
23
import PropTypes from 'prop-types';
34

45
import * as constants from './constants';
@@ -193,5 +194,5 @@ export default function traceLifecycle(ComponentToTrace) {
193194
delete TracedComponent.prototype.componentWillUpdate;
194195
}
195196

196-
return TracingComponent;
197+
return hoistStatics(TracingComponent, ComponentToTrace);
197198
}

test/TracedChild.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { traceLifecycle } from '../src';
44
class Child extends Component {
55
state = {}
66

7+
static staticProperty = 'a static property'
8+
79
constructor(props, context, trace) {
810
super(props, context, trace);
911
trace('custom:constructor');

test/integration.test.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ afterEach(() => {
4949
clearLog();
5050
});
5151

52+
describe('traceLifecycle', () => {
53+
it('preserves static properties', () => {
54+
expect(TracedChild.staticProperty).toBe('a static property');
55+
});
56+
});
57+
5258
describe('LifecyclePanel', () => {
5359
it('shows which methods are implemented', () => {
5460
wrapper.setState({isShowingChild: true}); // Mount TracedChild

0 commit comments

Comments
 (0)