---
title: withOptimizely for the React Native SDK
slug: feature-experimentation/docs/withoptimizely-reactnative-prior-to-v4
docTags: 
createdAt: 2026-08-05T20:39:54.000Z
---

By using the higher-order component (HoC) `withOptimizely`, any component under the OptimizelyProvider can access the Optimizely Feature Experimentation [ReactSDKClient](docId\:tuH8O0JxBYSmXLZDprLCN), which exposes Optimizely information and APIs.

## Version

SDK v2.2.0

## Description

The `withOptimizely` component provides access to all standard SDK methods, such as the Decide method, if you do not want to use React components or hooks (such as useDecision) to interact with Optimizely.  By providing the wrapped component with an `optimizely` prop, the withOptimizely higher-order component also makes using these standard SDK methods more convenient.

The `optimizely` object is automatically associated with the user prop passed to the ancestor OptimizelyProvider. The result is that the id and attributes from that user object will automatically be forwarded to all appropriate SDK method calls. So, there is no need to pass the userId or attributes arguments when calling methods of the `optimizely` client object after using `withOptimizely`, unless you want to use a different userId or attributes than those given to OptimizelyProvider.

## Parameters

This table lists the required and optional parameters for the React Native SDK.

| Parameter     | Type            | Description                                               |
| ------------- | --------------- | --------------------------------------------------------- |
| **Component** | React.Component | Component which will be enhanced with the following props |

## Props Provided

| Prop                       | Type                | Description                                                  |
| -------------------------- | ------------------- | ------------------------------------------------------------ |
| **optimizely**             | ReactSDKClient      | The client object which was passed to the OptimizelyProvider |
| **optimizelyReadyTimeout** | number \| undefined | The timeout which was passed to the OptimizelyProvider       |
| **isServerSide**           | boolean             | Value that was passed to the OptimizelyProvider              |

## Returns

A wrapped component with additional props as described above

## Example

```javascript
import { withOptimizely } from '@optimizely/react-sdk'

class MyComp extends React.Component {
  constructor(props) {
    super(props)
    const { optimizely } = this.props
    const decision = optimizely.decide('feat1')

    this.state = {
      decision.enabled,
      decision.variables,
    }
  }

  render() {
  }
}

const WrappedMyComponent = withOptimizely(MyComp)
```

## Track events using withOptimizely

```javascript
import { Button } from 'react-native';
import { withOptimizely } from '@optimizely/react-sdk';

class SignupButton extends React.Component {
  onPress = () => {
    const { optimizely } = this.props
    optimizely.onReady().then(() => {
      optimizely.track('signup-clicked')
    })
    // rest of click handler
  }

  render() {
    <Button onPress={this.onPress}>
      Signup
    </Button>
  }
}

const WrappedSignupButton = withOptimizely(SignupButton)
```

:::hint{type="warning"}
**Important**
As mentioned above, the `optimizely` client object provided through withOptimizely is automatically associated with the user prop passed to the ancestor OptimizelyProvider. There is no need to pass userId or attributes arguments when calling track, unless you want to use different userId or attributes than those given to OptimizelyProvider.
:::

## Source

The language/platform source files containing the implementation for React is [index.ts](https://github.com/optimizely/react-sdk/blob/master/src/index.ts).
