Skip to content

Commit 3f8c41c

Browse files
committed
First commit. TODO: migrate enzyme to rtl.
1 parent 883aa3e commit 3f8c41c

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"@types/jest": "^27.0.3",
4545
"@types/lodash.camelcase": "^4.3.6",
4646
"@types/prop-types": "^15.7.4",
47-
"@types/react": "^17.0.37",
48-
"@types/react-dom": "^17.0.11",
47+
"@types/react": "^18.0.0",
48+
"@types/react-dom": "^18.0.0",
4949
"@types/react-test-renderer": "^17.0.1",
5050
"@types/uuid": "^3.4.5",
5151
"enzyme": "^3.10.0",
@@ -55,9 +55,9 @@
5555
"jest-junit": "^13.0.0",
5656
"prettier": "^1.18.2",
5757
"prop-types": "^15.7.2",
58-
"react": "^17.0.0",
59-
"react-dom": "^17.0.0",
60-
"react-test-renderer": "^17.0.2",
58+
"react": "^18.0.0",
59+
"react-dom": "^18.0.0",
60+
"react-test-renderer": "^18.0.0",
6161
"rimraf": "^3.0.0",
6262
"ts-jest": "^27.1.1",
6363
"tslint": "^6.1.3",
@@ -72,7 +72,7 @@
7272
"uuid": "^3.3.2"
7373
},
7474
"peerDependencies": {
75-
"react": "^16.6.3 || ^17.0.0",
76-
"react-dom": "^16.8.4 || ^17.0.0"
75+
"react": "^16.6.3 || ^17.0.0 || ^18.0.0",
76+
"react-dom": "^16.8.4 || ^17.0.0 || ^18.0.0"
7777
}
7878
}

src/asyncWithLDProvider.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const renderWithConfig = async (config: AsyncProviderConfig) => {
3030

3131
const { getByText } = render(
3232
<LDProvider>
33-
<Consumer>{value => <span>Received: {JSON.stringify(value.flags)}</span>}</Consumer>
33+
<Consumer>{(value) => <span>Received: {JSON.stringify(value.flags)}</span>}</Consumer>
3434
</LDProvider>,
3535
);
3636

src/asyncWithLDProvider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, FunctionComponent } from 'react';
1+
import React, { useState, useEffect, FunctionComponent, PropsWithChildren, ReactNode } from 'react';
22
import { LDFlagSet, LDFlagChangeset } from 'launchdarkly-js-client-sdk';
33
import { AsyncProviderConfig, defaultReactOptions } from './types';
44
import { Provider } from './context';
@@ -34,7 +34,7 @@ export default async function asyncWithLDProvider(config: AsyncProviderConfig) {
3434
const reactOptions = { ...defaultReactOptions, ...userReactOptions };
3535
const { ldClient } = await initLDClient(clientSideID, user, reactOptions, options, targetFlags);
3636

37-
const LDProvider: FunctionComponent = ({ children }) => {
37+
const LDProvider = ({ children }: { children: ReactNode }) => {
3838
const [ldData, setLDData] = useState({
3939
flags: fetchFlags(ldClient, reactOptions, targetFlags),
4040
ldClient,
@@ -45,14 +45,14 @@ export default async function asyncWithLDProvider(config: AsyncProviderConfig) {
4545
const { bootstrap } = options;
4646
if (bootstrap && bootstrap !== 'localStorage') {
4747
const bootstrappedFlags = reactOptions.useCamelCaseFlagKeys ? camelCaseKeys(bootstrap) : bootstrap;
48-
setLDData(prev => ({ ...prev, flags: bootstrappedFlags }));
48+
setLDData((prev) => ({ ...prev, flags: bootstrappedFlags }));
4949
}
5050
}
5151

5252
ldClient.on('change', (changes: LDFlagChangeset) => {
5353
const flattened: LDFlagSet = getFlattenedFlagsFromChangeset(changes, targetFlags, reactOptions);
5454
if (Object.keys(flattened).length > 0) {
55-
setLDData(prev => ({ ...prev, flags: { ...prev.flags, ...flattened } }));
55+
setLDData((prev) => ({ ...prev, flags: { ...prev.flags, ...flattened } }));
5656
}
5757
});
5858
}, []);

src/initLDClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const initLDClient = async (
2525
const allOptions = { wrapperName: 'react-client-sdk', wrapperVersion: version, ...options };
2626
const ldClient = ldClientInitialize(clientSideID, user, allOptions);
2727

28-
return new Promise<AllFlagsLDClient>(resolve => {
28+
return new Promise<AllFlagsLDClient>((resolve) => {
2929
ldClient.on('ready', () => {
3030
const flags = fetchFlags(ldClient, reactOptions, targetFlags);
3131
resolve({ flags, ldClient });

src/provider.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('LDProvider', () => {
8080
const user1: LDUser = { key: 'yus', name: 'yus ng' };
8181
const user2: LDUser = { key: 'launch', name: 'darkly' };
8282
const options: LDOptions = { bootstrap: {} };
83-
const ldClient: Promise<LDClient> = new Promise(async resolve => {
83+
const ldClient: Promise<LDClient> = new Promise(async (resolve) => {
8484
resolve((await initLDClient(clientSideID, user1, defaultReactOptions, options, undefined)).ldClient);
8585

8686
return;
@@ -101,7 +101,7 @@ describe('LDProvider', () => {
101101
test('ld client is created if passed in promise resolves as undefined', async () => {
102102
const user: LDUser = { key: 'yus', name: 'yus ng' };
103103
const options: LDOptions = { bootstrap: {} };
104-
const ldClient: Promise<undefined> = new Promise(async resolve => {
104+
const ldClient: Promise<undefined> = new Promise(async (resolve) => {
105105
resolve(undefined);
106106

107107
return;

src/provider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import React, { Component, PropsWithChildren } from 'react';
22
import { LDClient, LDFlagSet, LDFlagChangeset } from 'launchdarkly-js-client-sdk';
33
import { EnhancedComponent, ProviderConfig, defaultReactOptions } from './types';
44
import { Provider, LDContext as HocState } from './context';
@@ -22,7 +22,7 @@ import { camelCaseKeys, fetchFlags, getFlattenedFlagsFromChangeset } from './uti
2222
* within your application. This provider is used inside the `withLDProviderHOC` and can be used instead to initialize
2323
* the `launchdarkly-js-client-sdk`. For async initialization, check out the `asyncWithLDProvider` function
2424
*/
25-
class LDProvider extends React.Component<ProviderConfig, HocState> implements EnhancedComponent {
25+
class LDProvider extends Component<PropsWithChildren<ProviderConfig>, HocState> implements EnhancedComponent {
2626
readonly state: Readonly<HocState>;
2727

2828
constructor(props: ProviderConfig) {

0 commit comments

Comments
 (0)