Skip to content

Instantly share code, notes, and snippets.

@n8rzz
Last active October 30, 2021 23:02
Show Gist options
  • Save n8rzz/e32bb6e85c456a7ba1238d743534e53d to your computer and use it in GitHub Desktop.
Save n8rzz/e32bb6e85c456a7ba1238d743534e53d to your computer and use it in GitHub Desktop.
ui-experiment.tsx
import React from 'react';
export enum ExperimentName {
a = 'a',
b = 'b',
}
export type Experiment = {
[key in ExperimentName]: React.ReactNode;
};
interface IProps extends Experiment {
/**
* Used to identify which component variant is active and should be rendered.
*
* When `true`, node passed via `b` is always rendered.
*/
isExperimentActive: boolean;
}
export const UiExperiment: React.FC<IProps> = (props) => {
return (
<React.Fragment>
{!props.isExperimentActive && props.a}
{props.isExperimentActive && props.b}
</React.Fragment>
);
};
UiExperiment.displayName = 'UiExperiment';
UiExperiment.defaultProps = {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment