Skip to content

Commit f40292b

Browse files
prepare 2.23 release (#72)
1 parent 23a09cd commit f40292b

4 files changed

Lines changed: 43 additions & 6 deletions

File tree

package-lock.json

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@testing-library/jest-dom": "^4.1.0",
3535
"@testing-library/react": "^11.2.6",
3636
"@types/enzyme": "^3.10.3",
37+
"@types/hoist-non-react-statics": "^3.3.1",
3738
"@types/jest": "^25.2.3",
3839
"@types/lodash.camelcase": "^4.3.6",
3940
"@types/prop-types": "^15.7.2",
@@ -58,6 +59,7 @@
5859
"typescript": "~3.8.3"
5960
},
6061
"dependencies": {
62+
"hoist-non-react-statics": "^3.3.2",
6163
"launchdarkly-js-client-sdk": "2.19.2",
6264
"lodash.camelcase": "^4.3.0",
6365
"uuid": "^3.3.2"

src/withLDProvider.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,17 @@ describe('withLDProvider', () => {
117117
expect(mockLDClient.on).toHaveBeenCalledWith('change', expect.any(Function));
118118
expect(newState).toEqual({ flags: { 'another-test-flag': false, 'test-flag': false } });
119119
});
120+
121+
test('hoist non react statics', () => {
122+
interface ComponentWithStaticFn extends React.FC {
123+
getInitialProps(): void;
124+
}
125+
const WrappedComponent: ComponentWithStaticFn = () => <></>;
126+
WrappedComponent.getInitialProps = () => '';
127+
128+
const LaunchDarklyApp = withLDProvider({ clientSideID, reactOptions: { useCamelCaseFlagKeys: false } })(
129+
WrappedComponent,
130+
) as ComponentWithStaticFn;
131+
expect(LaunchDarklyApp.getInitialProps).toBeDefined();
132+
});
120133
});

src/withLDProvider.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import { defaultReactOptions, ProviderConfig } from './types';
33
import LDProvider from './provider';
4+
import hoistNonReactStatics from 'hoist-non-react-statics';
45

56
/**
67
* `withLDProvider` is a function which accepts a config object which is used to
@@ -22,21 +23,25 @@ import LDProvider from './provider';
2223
* @param config - The configuration used to initialize LaunchDarkly's JS SDK
2324
* @return A function which accepts your root React component and returns a HOC
2425
*/
25-
export function withLDProvider(config: ProviderConfig) {
26-
return function withLDProviderHoc<P>(WrappedComponent: React.ComponentType<P>) {
26+
export function withLDProvider(config: ProviderConfig): (WrappedComponent: React.ComponentType) => React.ComponentType {
27+
return function withLDProviderHoc(WrappedComponent: React.ComponentType): React.ComponentType {
2728
const { reactOptions: userReactOptions } = config;
2829
const reactOptions = { ...defaultReactOptions, ...userReactOptions };
2930
const providerProps = { ...config, reactOptions };
3031

31-
return class extends React.Component<P> {
32+
class HoistedComponent extends React.Component {
3233
render() {
3334
return (
3435
<LDProvider {...providerProps}>
3536
<WrappedComponent {...this.props} />
3637
</LDProvider>
3738
);
3839
}
39-
};
40+
}
41+
42+
hoistNonReactStatics(HoistedComponent, WrappedComponent);
43+
44+
return HoistedComponent;
4045
};
4146
}
4247

0 commit comments

Comments
 (0)