@the-control-group/react-split-test
Version:
A/B Split Testing Component for React
30 lines (29 loc) • 1.1 kB
TypeScript
import React, { Component, PropsWithChildren } from 'react';
type ExperimentProps = PropsWithChildren<{
id: string;
session?: boolean;
onParticipate: (experimentData: {
id: string;
selectedVariation: string;
}) => void;
variationDecider: (experimentChildren: React.ReactNode) => Promise<string>;
}>;
export default class Experiment extends Component<ExperimentProps, {
selectedVariation: string | null;
}> {
private storage;
private cacheKey;
static defaultProps: {
onParticipate: () => void;
/**
* Stub A/B decider
* @param {React.node} experimentChildren - React children nodes of the experiment
* @return {Promise<variation id>} Selected variation ID
*/
variationDecider: (experimentChildren: React.ReactNode) => Promise<string>;
};
constructor(props: ExperimentProps);
chooseVariation(): string | null;
render(): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>)[] | null | undefined;
}
export {};