Check which variation of an experiment is assigned to a user. A userId
and attributes
could be optionally supplied.
import { useExperiment } from 'react-tesfy';const Component = () => {const variationId = useExperiment({ id: 'experiment-1' }); // '1'// orconst userId = '676380e0-7793-44d6-9189-eb5868e17a86';const attributes = { countryCode: 'us' };const variationId = useExperiment({id: 'experiment-1',userId,attributes}); // '1'};
import { Experiment, Variation } from 'react-tesfy';const userId = '676380e0-7793-44d6-9189-eb5868e17a86';const attributes = { countryCode: 'us' };const Component = () => (<Experiment id="experiment-1" userId={userId} attributes={attributes}><Variation>Not rendered</Variation><Variation id="0">Not rendered</Variation><Variation id="1">Rendered</Variation></Experiment>);