Skip to content

Instantly share code, notes, and snippets.

@juliandavidmr
Last active August 9, 2023 20:20
Show Gist options
  • Save juliandavidmr/c8f537b6083577a262609894d0712fbf to your computer and use it in GitHub Desktop.
Save juliandavidmr/c8f537b6083577a262609894d0712fbf to your computer and use it in GitHub Desktop.
2022 useExperiment.ts
import { useContext } from 'react';
import {
AmplitudeExperimentContext,
AmplitudeExperimentContextValue,
} from './ExperimentContext';
const useExperiment = (): AmplitudeExperimentContextValue => {
const context = useContext(AmplitudeExperimentContext);
if (context === undefined) {
throw new Error(
'useExperiment must be used within a AmplitudeExperimentProvider',
);
}
return context!;
};
export default useExperiment;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment