# @atlaskit/react-experiment-framework

> Experimentation React components

Latest version **0.9.0** (published 2024-08-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @atlaskit/react-experiment-framework
pnpm add @atlaskit/react-experiment-framework
yarn add @atlaskit/react-experiment-framework
bun add @atlaskit/react-experiment-framework
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2024-08-23 |
| First published | 2018-09-06 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 78.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Atlassian Pty Ltd |
| Maintainers | atlaskit |

## Links

- npm: https://www.npmjs.com/package/@atlaskit/react-experiment-framework
- Repository: https://bitbucket.org/atlassian/atlassian-frontend-mirror
- Homepage: https://bitbucket.org/atlassian/atlassian-frontend-mirror#readme
- Issues: https://bitbucket.org/atlassian/atlassian-frontend-mirror/issues
- npm.io page: https://npm.io/package/@atlaskit/react-experiment-framework

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.0.0

## Recent versions

- 0.9.0 (latest) — 2024-08-23
- 0.8.2 (next) — 2023-05-17
- 0.8.4 — 2024-03-20
- 0.8.3 — 2024-01-25
- 0.8.1 — 2023-05-15
- 0.8.0 — 2023-05-08
- 0.7.7 — 2022-10-04
- 0.7.6 — 2022-08-25
- 0.7.5 — 2022-04-26
- 0.7.4 — 2021-04-23
- 0.7.3 — 2020-11-19
- 0.7.2 — 2020-10-15
- 0.7.1 — 2020-08-24
- 0.7.0 — 2020-07-02
- 0.6.4 — 2020-05-25
- … 14 more at https://npm.io/package/@atlaskit/react-experiment-framework/versions

## README

# README

## What is this package for?

A set of React components that facilitate experimentation in product, by allowing React
components to be swapped dynamically at run-time.

## Installing the framework

```sh
npm i -S @atlaskit/react-experiment-framework
```

## Usage

Wrap your React app in the ExperimentController component

```js
import { ExperimentController } from '@atlaskit/react-experiment-framework';

ReactDOM.render(
  <ExperimentController experimentEnrollmentConfig={experimentEnrollmentConfig}>
    <App />
  </ExperimentController>,
  document.getElementById('root'),
);
```

The experimentEnrollmentConfig prop provided to the ExperimentController should be a map of experimentKey (string) to an enrollmentResolver. The resolver should return a promise that resolves to a cohort and provide eligiblity details of the user for the experiment

```js

// example of a resolver
import type { EnrollmentDetails, ExperimentEnrollmentConfig } from '@atlaskit/react-experiment-framework';

const experimentEnrollmentResolver = async (): EnrollmentDetails => {
    // example where the cohort is provided by an async feature flag fetch, e.g., LD client, or graphql query
    const featureFlagValue = await getFeatureFlag('myExperimentFeatureFlag');

    return {
        cohort: featureFlagValue,
        isEligble: true,
        ineligibilityReasons: null
    };
}

// example of experiment enrollment config
const experimentEnrollmentConfig: ExperimentEnrollmentConfig = {
    myExperimentKey: experimentEnrollmentResolver,
    ...,
};
```

The above sets up the react context provider for experimentation.

Then to set up your experiment, wrap an existing React Component in your app with the Higher Order Component / function, asExperiment.

```js

// Your original component that provides the current experience you intend to swap with the experiment
class ExistingComponent extends React.Component {
    ...
}

// Your new component that provides the experimental experience
class ExperimentReplacementComponent extends React.Component {
    ...
}

export default asExperiment({
    // example cohort names used here, control and variant, but they can be whatever you like
    control: ExistingComponent,
    variant: ExperimentReplacementComponent,

    // fallback is not optional, however, this is what is rendered in the event of a error encountered or when the user
    // is ineligible
    fallback: ExistingComponent,
}, 'myExperimentKey',
{
    // callbacks to trigger tracking on exposure and errors, these are just examples provide your own
    onExposure: (data) => analyticsClient.trigger('experiment-exposure', data),
    onError: (data) => analyticsClient.trigger('experiment-error', data)
},
    // optional component to show while enrollment is being resolved. When absent, renders null during resolution.
    Spinner,
);
```

---
_Source: https://npm.io/package/@atlaskit/react-experiment-framework · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
