Splitfactory config in react js
Hi
I have a component which setups my config in constructor
this.config = {
core: {
authorizationKey: splitioConfig.apiKey,
key: this.props.user ? this.props.user.id : -1
}
}
BUT at this point the user props wont exist until
componentDidUpdate(prevProps, prevState, snapshot) {
if (prevProps.user !== this.props.user) {
In which case Ill now receive the correct user
However
<SplitFactory config={this.config}>
<SplitTreatments names={this.featureNames}>
{({ treatments, isReady }) => {
console.log('isReady ', isReady);
if (isReady) {
In my render it seems the factory is setup and thus never updates?
As its always showing
isReady true
treatment off
despite eventually seeing the console.log where the user is now existing
updateUser {id: 788750 ....
Am I doing something wrong?
-
Hi Jason,
At the time of Split factory initialization, looks like the user id passed is -1, since the prop is not available yet, which will not calculate the treatment for the actual user id.
Once the user prop is available, create another client object from the same factory object using the correct user id, checkout this docs link on how to do it with the React SDK: https://help.split.io/hc/en-us/articles/360038825091-React-SDK#advanced-instantiate-multiple-sdk-clients
Thanks
Bilal
-
I have tried this long back ...
-
Hi John, I just added this KB for lazy init of SDK: https://help.split.io/hc/en-us/articles/360046771911-React-SDK-Lazy-initialization-of-Split-client
Thanks
Bilal
Please sign in to leave a comment.
Comments
3 comments