-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSplitClient.tsx
More file actions
26 lines (24 loc) · 849 Bytes
/
SplitClient.tsx
File metadata and controls
26 lines (24 loc) · 849 Bytes
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
import * as React from 'react';
import { SplitContext } from './SplitContext';
import { ISplitClientProps } from './types';
import { useSplitClient } from './useSplitClient';
/**
* SplitClient will initialize a new SDK client and listen for its events in order to update the Split Context.
* Children components will have access to the new client when accessing Split Context.
*
* The underlying SDK client can be changed during the component lifecycle
* if the component is updated with a different splitKey prop.
*/
export function SplitClient(props: ISplitClientProps) {
const { children } = props;
const context = useSplitClient(props);
return (
<SplitContext.Provider value={context}>
{
typeof children === 'function' ?
children(context) :
children
}
</SplitContext.Provider>
)
}