My feature is enabled
} - { !decision.enabled &&My feature is disabled
} - { decision.variationKey === 'control-variation' &&Current Variation
} - { decision.variationKey === 'experimental-variation' &&Better Variation
} + {decision.enabled &&My feature is enabled
} + {!decision.enabled &&My feature is disabled
} + {decision.variationKey === 'control-variation' &&Current Variation
} + {decision.variationKey === 'experimental-variation' &&Better Variation
} > ); @@ -332,23 +333,22 @@ function MyComponent() { ``` ### Tracking + Use the built-in `useTrackEvent` hook to access the `track` method of optimizely instance ```jsx import { useTrackEvent } from '@optimizely/react-sdk'; function SignupButton() { - const [track, clientReady, didTimeout] = useTrackEvent() + const [track, clientReady, didTimeout] = useTrackEvent(); const handleClick = () => { - if(clientReady) { - track('signup-clicked') + if (clientReady) { + track('signup-clicked'); } - } + }; - return ( - - ) + return ; } ``` @@ -385,25 +385,27 @@ The following type definitions are used in the `ReactSDKClient` interface: `ReactSDKClient` instances have the methods/properties listed below. Note that in general, the API largely matches that of the core `@optimizely/optimizely-sdk` client instance, which is documented on the [Optimizely Feature Experimentation developer docs site](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/welcome). The major exception is that, for most methods, user id & attributes are **_optional_** arguments. `ReactSDKClient` has a current user. This user's id & attributes are automatically applied to all method calls, and overrides can be provided as arguments to these method calls if desired. -- `onReady(opts?: { timeout?: number }): PromiseFeature enabled
:Feature disabled
; +} -2. Rendering of components must be completely synchronous (this is true for all server side rendering), thus the Optimizely SDK assumes that the optimizely client has been instantiated and fired it's `onReady` event already. +The feature is enabled
} - { !decision.enabled &&The feature is not enabled
} - { decision.variationKey === 'variation1' &&Variation 1
} - { decision.variationKey === 'variation2' &&Variation 2
} -