-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathuseSplitManager.ts
More file actions
29 lines (26 loc) · 1.11 KB
/
useSplitManager.ts
File metadata and controls
29 lines (26 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { useSplitClient } from './useSplitClient';
import { IUseSplitManagerResult } from './types';
import { useSplitContext } from './SplitContext';
/**
* `useSplitManager` is a hook that returns an Split Context object with the manager instance from the Split factory.
*
* @returns A Split Context object merged with the manager and its status.
*
* @example
* ```js
* const { manager, isReady, isReadyFromCache, lastUpdate, ... } = useSplitManager();
* ```
*
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/javascript-sdk/#manager}
*/
export function useSplitManager(): IUseSplitManagerResult {
// @TODO refactor next lines to `const context = useSplitClient();` when `SplitClient` is removed
// This is required to avoid retrieving the status of a non-default client if context was updated by a `SplitClient` component.
const { factory } = useSplitContext();
const context = useSplitClient({ splitKey: factory?.settings.core.key });
const manager = factory ? factory.manager() : undefined;
return {
...context,
manager,
};
}