Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI Reference
Dev guideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Update usage from older versions of the React Native SDK

Describes how to update from older versions of the Optimizely Full Stack (Legacy) React Native SDK to Optimizely Feature Experimentation.

This section provides code examples for how Optimizely recommends leveraging the new Decision and Event Tracking APIs. All existing Full Stack (Legacy) methods and implementation are still supported. See Optimizely Feature Experimentation - application & migration documentation for the latest updates.

Optimizely recommends adopting the new Decide, Decide All, and Track Event methods as a more flexible and easier-to-use replacement where you currently use isFeatureEnabled, getFeatureVariable, getAllFeatures, or Track calls within your implementation.

The following are examples of how to migrate the Full Stack (Legacy) methods to Feature Experimentation methods:

// -------------------------------
// Optimizely Feature
// -------------------------------
// old method using Feature component
function MyFeature() {
  return (
    <OptimizelyFeature feature="flag1">
      {(isEnabled, variables) => <Text>{isEnabled} - {variables}</Text>}
    </OptimizelyFeature>
  );
}

// old method using Feature hook
function MyFeature() {
  const [isEnabled, variables] = useFeature('flag1');
  return <Text>{isEnabled} - {variables}</Text>;
}

// new method
function MyFeature() {
  const [decision] = useDecision('flag1');
  return <Text>{decision.enabled} - {decision.variables}</Text>;
}

// -------------------------------
// Optimizely Experiment
// -------------------------------
// old method using Experiment component
function MyExperiment() {
  return (
    <OptimizelyExperiment experiment='experiment1'>
      <OptimizelyVariation variation='firstvariation'>
        <Text>First Variation</Text>
      </OptimizelyVariation>
      <OptimizelyVariation variation='secondvariation'>
        <Text>Second Variation</Text>
      </OptimizelyVariation>
    </OptimizelyExperiment>
  );
}

// old method using Experiment hook
function MyExperiment() {
  const [variation] = useExperiment('experiment1');
  return (
    <>
      {variation === 'firstvariation' && <Text>First Variation</Text>}
      {variation === 'secondvariation' && <Text>Second Variation</Text>}
    </>
  );
}

// new method
function MyExperiment() {
  //decide hook uses flag key. New Api does not support flag-less experiments
  const [decision] = useDecision('flagfor_experiment1');
  return (
    <>
      {decision.variationKey === 'firstvariation' && <Text>First Variation</Text>}
      {decision.variationKey === 'secondvariation' && <Text>Second Variation</Text>}
    </>
  );
}

// -------------------------------
// Track 
// ------------------------------
// unlike other SDKs, no change from old method (optimizely_client.track)