splitio-react
v1.1.0
Published
react split-io wrapper library
Downloads
429
Readme
splitio-react
Dependency
This package assumes you would import splitio use CDN (recommended in docs https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK).
<script src="//cdn.split.io/sdk/split-10.8.2.min.js"></script>
Install
yarn add splitio-react
Config
import { SplitIOProvider } from 'splitio-react';
const App = () => (
<SplitIOProvider
splitKey={'CUSTOMER_ID'}
authorizationKey={'SPLIT_IO_API_KEY'}
attributes={{
attrA,
attrB,
attrC,
...otherAttrs
}}
splits={[SPLIT_NAMES]}
>
<Main />
</SplitIOProvider>
)
Usage
import { useSplitTreatment } from 'splitio-react';
const SplitView = () => {
const treatmentValue = useSplitTreatment('SPLIT_NAME');
const client = useSplitClient();
useEffect(() => {
if (treatmentValue === 'on') {
client.track('traffic type', 'event');
}
}, [treatmentValue]);
return treatmentValue === 'on' ? <div>On</div> : <div>Off</div>
};