Question
Using the React SDK, is it possible to get Split treatments through Javascript code in addition to using the SDK React components?
Answer
Yes, it is possible. The React SDK is created on top of the same Javascript SKD core, so it supports all the objects and functions provided in it.
The code below can be used to get treatment using the same factory object created initially:
import { SplitSdk } from "@splitsoftware/splitio-react"
const splitFactory = SplitSdk({
core: {
authorizationKey: 'YOUR_BROWSER_API_KEY',
key: 'key'
}
})
// create new client object
const client = splitFactory.client("userId");
const treatment = client.getTreatment("splitName");
Comments
3 comments
Is this a typo or how are we calling client() on the sdkConfig objec?
After playing with this for a bit, I think what they were going for was:
It would seem that if you wrap your config object in `SplitSdk`, it will instantiate the factory for you, which will have `client()` available for you to call.
Thanks kliu I updated the article.
Please sign in to leave a comment.