Skip to content

Instantly share code, notes, and snippets.

@juliandavidmr
Created August 9, 2023 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliandavidmr/77839a29c85574d2f4b112161ee5c292 to your computer and use it in GitHub Desktop.
Save juliandavidmr/77839a29c85574d2f4b112161ee5c292 to your computer and use it in GitHub Desktop.
2022 ExperimentContext.ts
import { createContext } from 'react';
import { ExperimentClient } from '@amplitude/experiment-js-client';
export interface AmplitudeExperimentContextValue {
experiment?: ExperimentClient;
isVariantActive: (variantId: string, variantValue?: string) => boolean;
/**
* @description Returns true if the user is in the experiment with variant `control`.
*/
isControlActive: (variantId: string, defaultControl?: string) => boolean;
getPayloadVariant: <T>(variantId: string) => T | null;
}
export const AmplitudeExperimentContext =
createContext<AmplitudeExperimentContextValue | null>(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment