Skip to content

Commit 596cf92

Browse files
Merge pull request #251 from splitio/migration-guide-update
Update MIGRATION-GUIDE.md
2 parents 54aaea6 + 9a58781 commit 596cf92

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

MIGRATION-GUIDE.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,32 @@
33

44
React SDK v2.0.0 has a few breaking changes that you should consider when migrating from a previous version. The main changes are:
55

6-
### • Deprecated `useClient`, `useTreatments`, and `useManager` hooks have been removed.
76

8-
Follow [this section](#migrating-to-get-react-sdk-v1100-improvements-replacing-the-deprecated-useclient-usetreatments-and-usemanager-hooks) to migrate to the new hooks `useSplitClient`, `useSplitTreatments`, and `useSplitManager`.
7+
### `useTreatments` hook was removed in v2.0.0, but re-introduced in v2.6.0 with a different API:
8+
9+
Since v2.6.0, there are 4 hooks variants to evaluate feature flags, to better cover the different evaluation methods available in the JavaScript SDK client:
10+
11+
- `useTreatment`: returns a treatment value for a given feature flag name. It calls `client.getTreatment()` method under the hood.
12+
- `useTreatmentWithConfig`: returns a single treatment value and its configuration for a given feature flag name. It calls `client.getTreatmentWithConfig()` method under the hood.
13+
- `useTreatments`: returns an object with treatment values for multiple feature flag names. It calls `client.getTreatments()` or `client.getTreatmentsByFlagSets()` methods under the hood, depending if the `names` or `flagSets` option is provided.
14+
- `useTreatmentsWithConfig`: returns an object with treatment values and their configurations for multiple feature flag names. It calls `client.getTreatmentsWithConfig()` or `client.getTreatmentsWithConfigByFlagSets()` methods under the hood, depending if the `names` or `flagSets` option is provided.
15+
16+
The `useTreatments` hook from v1.x.x should be replaced with `useTreatmentsWithConfig`, as follows:
17+
18+
```javascript
19+
// v1.x.x
20+
const treatments = useTreatments(featureFlagNames, optionalAttributes, optionalSplitKey);
21+
22+
// v2.6.0+
23+
const { treatments } = useTreatmentsWithConfig({ names: featureFlagNames, attributes: optionalAttributes, splitKey: optionalSplitKey });
24+
25+
// v2.0.0-v2.5.0
26+
const { treatments } = useSplitTreatments({ names: featureFlagNames, attributes: optionalAttributes, splitKey: optionalSplitKey });
27+
```
28+
29+
### • Deprecated `useClient` and `useManager` hooks have been removed.
30+
31+
Follow [this section](#migrating-to-get-react-sdk-v1100-improvements-replacing-the-deprecated-useclient-usetreatments-and-usemanager-hooks) to migrate to the new hooks `useSplitClient` and `useSplitManager`.
932

1033
### • Updated the default value of `updateOnSdkUpdate` and `updateOnSdkTimedout` options to `true`.
1134

@@ -15,7 +38,7 @@ Consider setting the `updateOnSdkUpdate` option to `false` to revert to the prev
1538

1639
The same applies for the equivalent props in the `[with]SplitClient` and `[with]SplitTreatments` components, although these components are deprecated and we recommend [migrating to their hook alternatives](#-high-order-components-withsplitclient-withsplittreatments-and-components-that-accept-a-render-function-as-child-component-splittreatments-and-splitclient-have-been-deprecated-and-might-be-removed-in-a-future-major-release).
1740

18-
### • Deprecated `SplitFactory` provider has been removed, `withSplitFactory` is deprecated, and `SplitFactoryProvider` doesn't accept `updateOn` props and a render function as children anymore.
41+
### • Deprecated `SplitFactory` provider has been removed, `withSplitFactory` is deprecated, and `SplitFactoryProvider` doesn't accept a render function as children anymore.
1942

2043
To migrate your existing code to the new version of `SplitFactoryProvider`, consider the following refactor example:
2144

@@ -53,21 +76,21 @@ should be refactored to:
5376

5477
```tsx
5578
const MyComponent = () => {
56-
const props: ISplitContextValues = useSplitClient({ updateOnSdkUpdate: false });
79+
const props: ISplitContextValues = useSplitClient();
5780
const { factory, client, isReady, isReadyFromCache, ... } = props;
5881
...
5982
};
6083

6184
const App = () => {
6285
return (
63-
<SplitFactoryProvider config={mySplitConfig} attributes={DEFAULT_CLIENT_ATTRIBUTES} >
86+
<SplitFactoryProvider config={mySplitConfig} updateOnSdkUpdate={false} attributes={DEFAULT_CLIENT_ATTRIBUTES} >
6487
<MyComponent />
6588
</SplitFactoryProvider>
6689
);
6790
};
6891
```
6992

70-
Notice that `MyComponent` was refactored to use the `useSplitClient` hook and is passed as a React JSX element rather than a render function. The `useSplitClient` hook is called without providing a `splitKey` param. This means that the default client (whose key is set in the `core.key` property of the `mySplitConfig` object) will be used, and the `updateOnSdkUpdate` and `attributes` props are passed as options to the hook.
93+
Notice that `MyComponent` was refactored to use the `useSplitClient` hook and is passed as a React JSX element rather than a render function. The `useSplitClient` hook is called without providing a `splitKey` param. This means that the default client (whose key is set in the `core.key` property of the `mySplitConfig` object) will be used.
7194

7295
### • High-Order-Components (`withSplitClient`, `withSplitTreatments`) and components that accept a render function as child component (`SplitTreatments`, and `SplitClient`) have been deprecated and might be removed in a future major release.
7396

0 commit comments

Comments
 (0)