---
title: useDecision hook for the React SDK
slug: feature-experimentation/docs/usedecision-react-prior-to-v4
docTags: 
createdAt: 2026-08-05T20:39:51.000Z
---

**Minimum SDK version** – v2.5+

## `useDecision` hook

Retrieves the decision result for a flag key, optionally auto-updating that decision based on underlying user, datafile, or forced decision changes.

### Arguments

| Argument                 | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \`flagKey \`(required)   | String | The key of the feature flag                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| \`options \`(optional)   | Object | Includes the following:<br />- \`autoUpdate\` (boolean) - If true, this hook updates the flag decision in response to datafile or user changes. Default: \`false\`.<br />- \`timeout\` (number) - Client timeout as described in the \[\`OptimizelyProvider\`]\(https\://docs.developers.optimizely.com/feature-experimentation/docs/optimizelyprovider-react-prior-to-v4) documentation. Overrides any timeout set on the ancestor \`OptimizelyProvider\`.<br />- \`decideOptions\` (\`OptimizelyDecideOption\`) - Array of \`OptimizelyDecideOption\` enums. See \[OptimizelyDecideOption]\(#optimizelydecideoption). |
| \`overrides \`(optional) | Object | Includes the following:<br />- \`overrideUserId\` (string) - Override the userId to be used to obtain the decision result for this hook.<br />- \`overrideAttributes\` (optimizely.UserAttributes) – Override the user attributes to be used to obtain the decision result for this hook.                                                                                                                                                                                                                                                                                                                               |

### Returns

Returns an array with the following:

| Key             | Type                                                                                                                              | Description                                                                                                                                                                                                                                     |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \`decision\`    | \[OptimizelyDecision]\(https\://docs.developers.optimizely.com/feature-experimentation/docs/optimizelydecision-react-prior-to-v4) | Decision result for the flag key.                                                                                                                                                                                                               |
| \`clientReady\` | Boolean                                                                                                                           | Indicates whether the \`ReactSDKClient\` instance is ready.                                                                                                                                                                                     |
| \`didTimeout\`  | Boolean                                                                                                                           | Indicates whether the \`ReactSDKClient\` instance became ready within the allowed timeout range. \`clientReady\` can be \`true\` even if \`didTimeout\` is also \`true\`. This indicates that the client became ready after the timeout period. |

### Example `useDecision`

```javascript
import { useEffect } from 'react';
import { useDecision } from '@optimizely/react-sdk';

function LoginComponent() {
  const [decision, clientReady] = useDecision(
    'flag1',
    { autoUpdate: true },
    {
      /* (Optional) User overrides */
    }
  );
  useEffect(() => {
    document.title = decision.enabled ? 'New Feature flag' : 'Old Feature flag';
  }, [decision]);

  return (
    <p>
      <a href={decision.variationKey === 'login1' ? '/login' : '/login2'}>Click to login</a>
    </p>
  );
}
```

## `OptimizelyDecideOption`

The following table lists the `OptimizelyDecideOption` enum with an explanation what happens if you set them. In addition to setting these options individually for a decide method, you can also set them as global defaults when you instantiate the Optimizely client. See [Initialize the React SDK](docId\:DNHADl7EzUwjramceiCdz).

| `OptimizelyDecideOption` enum                        | If set                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `OptimizelyDecideOption.DISABLE_DECISION_EVENT`      | Prevents the SDK from dispatching an [impression](../../end-user-docs/measure-and-analyze-results/what-are-impressions-and-decisions-in-feature-experimentation.mdx) event when serving a variation. This disables decision tracking on the [Optimizely Experiment Results page](../../end-user-docs/measure-and-analyze-results/optimizely-experiment-results-page.mdx). The [decision notification listener](../../developer-docs/configure/notification-listeners/decision-notification-listener.mdx) is still called, with `decisionEventDispatched` set to `false`. |
| `OptimizelyDecideOption.ENABLED_FLAGS_ONLY`          | Returns decisions only for flags that are currently enabled. Used with the decide all method and decide for keys method.<br />When this option is not set, the SDK returns all decisions regardless of whether the flag is enabled.                                                                                                                                                                                                                                                                                                                                      |
| `OptimizelyDecideOption.IGNORE_USER_PROFILE_SERVICE` | Bypasses the user profile service (both lookup and save) for the decision.<br />When this option is not set, user profile service overrides audience targeting, traffic allocation, and experiment mutual exclusion groups.                                                                                                                                                                                                                                                                                                                                              |
| `OptimizelyDecideOption.INCLUDE_REASONS`             | Adds log messages to the reasons field of the decision. Critical errors are always returned, even if this option is not set.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `OptimizelyDecideOption.EXCLUDE_VARIABLES`           | Excludes flag variable values from the decision result. Use this option to minimize the returned decision by skipping large JSON variables.                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `OptimizelyDecideOption.IGNORE_CMAB_CACHE`           | Bypasses the CMAB cache and fetches a fresh decision from the CMAB service. Use when you need real-time decisions that reflect the latest context.                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `OptimizelyDecideOption.INVALIDATE_USER_CMAB_CACHE`  | Removes the cached CMAB decision for this user and experiment before making the decision. Use when user context has changed significantly and you want to ensure a fresh decision.                                                                                                                                                                                                                                                                                                                                                                                       |
| `OptimizelyDecideOption.RESET_CMAB_CACHE`            | Clears all entries from the CMAB cache before making the decision. Use sparingly for testing or cache corruption scenarios.                                                                                                                                                                                                                                                                                                                                                                                                                                              |

The following example shows how you can set options individually on the `useDecision` hook, or as global defaults when you instantiate the Optimizely client. See [Initialize React SDK](docId\:DNHADl7EzUwjramceiCdz).

```javascript
import { useEffect } from 'react';
import {
  createInstance,
  OptimizelyProvider,
  useDecision,
  OptimizelyDecideOption,
} from '@optimizely/react-sdk';

// Instantiate an Optimizely client
const optimizelyClient = createInstance({
  sdkKey: 'Your_SDK_Key', // Replace with your SDK key
  defaultDecideOptions: [OptimizelyDecideOption.DISABLE_DECISION_EVENT],
});

function LoginComponent() {
  const [decision, clientReady] = useDecision(
    'flag1',
    {
      autoUpdate: true,
      decideOptions: [
        OptimizelyDecideOption.ENABLED_FLAGS_ONLY,
        OptimizelyDecideOption.IGNORE_USER_PROFILE_SERVICE,
      ],
    },
    {
      /* (Optional) User overrides */
    }
  );
  useEffect(() => {
    document.title = decision.enabled ? 'New Feature flag' : 'Old Feature flag';
  }, [decision]);

  return (
    <p>
      <a href={decision.variationKey === 'login1' ? '/login' : '/login2'}>Click to login</a>
    </p>
  );
}

function App() {
  return (
    <OptimizelyProvider optimizely={optimizelyClient} user={{ id: 'user123' }}>
      <LoginComponent />
    </OptimizelyProvider>
  );
}
```
