Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo
Mode
Accessibility
Vuetify

useFeatures

Manage feature flags and simple variations across your app. Register features, toggle them, and query a variation value for A/B-style behavior.

Intermediate94.8% coverageJan 23, 2026

Usage

Install the Features plugin once, then access the context anywhere via createFeatures.

ts
import { createApp } from 'vue'
import { createFeaturesPlugin } from '@vuetify/v0'
import App from './App.vue'

const app = createApp(App)

app.use(
  createFeaturesPlugin({
    features: {
      analytics: true,
      debug_mode: false,
      notifications: false,
      search: { $value: true, $variation: 'v2' },
    },
  })
)

app.mount('#app')

Now in any component, access current feature flags and variations:

UseFeatures
<script setup lang="ts">
  import { useFeatures } from '@vuetify/v0'

  const features = useFeatures()
</script>

<template>
  <div>
    <p>Analytics: {{ features.get('analytics') }}</p>
    <p>Debug Mode: {{ features.get('debug_mode') }}</p>
    <p>Notifications: {{ features.get('notifications') }}</p>
    <p>Search Variation: {{ features.variation('search', 'v1') }}</p>
  </div>
</template>

Optionally register features at runtime:

UseFeatures
<script setup lang="ts">
  import { useFeatures } from '@vuetify/v0'

  const features = useFeatures()

  // Register at runtime
  features.register({ id: 'beta', value: false })

  // Enable/disable via selection helpers
  features.select('beta')
  features.unselect('analytics')
</script>

Adapters

useFeatures supports an adapter pattern to integrate with external feature flag providers.

Built-in Adapters

Vuetify 0 includes adapters for popular feature flag services. Each adapter is imported from its own subpath to avoid bundling unused provider SDKs.

Flagsmith

Requires flagsmith package.

ts
import flagsmith from 'flagsmith'
import { FlagsmithFeatureAdapter } from '@vuetify/v0/features/flagsmith'

app.use(createFeaturesPlugin({
  adapter: new FlagsmithFeatureAdapter(flagsmith, {
    environmentID: '<YOUR_ENV_ID>',
    // ...other flagsmith options
  })
}))

LaunchDarkly

Requires launchdarkly-js-client-sdk package.

ts
import * as LDClient from 'launchdarkly-js-client-sdk'
import { LaunchDarklyFeatureAdapter } from '@vuetify/v0/features/launchdarkly'

const client = LDClient.initialize('<YOUR_CLIENT_SIDE_ID>', { key: 'user-key' })

await client.waitForInitialization()

app.use(createFeaturesPlugin({
  adapter: new LaunchDarklyFeatureAdapter(client)
}))

PostHog

Requires posthog-js package.

ts
import posthog from 'posthog-js'
import { PostHogFeatureAdapter } from '@vuetify/v0/features/posthog'

posthog.init('<YOUR_PROJECT_API_KEY>', { api_host: 'https://app.posthog.com' })

app.use(createFeaturesPlugin({
  adapter: new PostHogFeatureAdapter(posthog)
}))

Multiple Adapters

You can combine flags from multiple sources by passing an array of adapters. They are initialized in order, and flags are merged (last one wins for conflicting keys).

ts
import { FlagsmithFeatureAdapter } from '@vuetify/v0/features/flagsmith'
import { PostHogFeatureAdapter } from '@vuetify/v0/features/posthog'

app.use(createFeaturesPlugin({
  adapter: [
    new FlagsmithFeatureAdapter(flagsmith, options),
    new PostHogFeatureAdapter(posthog),
  ]
}))

Custom Adapters

Create custom adapters by implementing the FeaturesAdapterInterface.

ts
import type { FeaturesAdapterInterface, FeaturesAdapterFlags } from '@vuetify/v0'

class WindowFeaturesAdapter implements FeaturesAdapterInterface {
  setup (onUpdate: (flags: FeaturesAdapterFlags) => void): FeaturesAdapterFlags {
    const update = (event: CustomEvent) => {
      onUpdate(event.detail)
    }

    window.addEventListener('v0:update-features', update as EventListener)

    this.disposeFn = () => {
      window.removeEventListener('v0:update-features', update as EventListener)
    }

    // Return initial state if available, or empty object
    return window.__INITIAL_FEATURES__ || {}
  }

  dispose () {
    this.disposeFn()
  }

  private disposeFn = () => {}
}

Adapter Interface

The adapter pattern decouples feature flags from the underlying provider.

Adapter Data Flow

Use controls to zoom and pan. Click outside or press Escape to close.

Adapter Data Flow
ts
interface FeaturesAdapterInterface {
  /**
   * Initialize the adapter and return initial flags.
   *
   * @param onUpdate Callback invoked when flags change.
   * @returns Initial feature flags.
   */
  setup: (onUpdate: (flags: FeaturesAdapterFlags) => void) => FeaturesAdapterFlags

  /**
   * Cleanup adapter resources.
   */
  dispose?: () => void
}

Architecture

useFeatures extends createGroup for multi-selection and createTokens for variations:

Features Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Features Hierarchy

API Reference

The following API details are for the useFeatures composable.

Functions

createFeatures

(_options?: FeatureOptions) => R

Creates a new features instance.

createFeaturesContext

(_options?: FeatureContextOptions) => ContextTrinity<R>

Creates a new features context.

createFeaturesPlugin

(_options?: FeaturePluginOptions) => any

Creates a new features plugin.

useFeatures

(namespace?: string) => R

Returns the current features instance.

Options

events

boolean

Enable event emission for registry operations

Default: false

reactive

boolean

Enable reactive behavior for registry operations

Default: false

features

Record<ID, any>

Static feature flags to register.

Properties

collection

ReadonlyMap<ID, Z>

The collection of tickets in the registry

size

number

The number of tickets in the registry

selectedIds

Reactive<Set<ID>>

Set of selected ticket IDs

selectedItems

ComputedRef<Set<E>>

Set of selected ticket instances

selectedValues

ComputedRef<Set<unknown>>

Set of selected ticket values

disabled

MaybeRef<boolean>

Disable state for the entire selection instance

selectedIndexes

ComputedRef<Set<number>>

mixedIds

Reactive<Set<ID>>

Set of mixed/indeterminate ticket IDs

mixedItems

ComputedRef<Set<E>>

Set of mixed/indeterminate ticket instances

isNoneSelected

ComputedRef<boolean>

Whether no items are currently selected

isAllSelected

ComputedRef<boolean>

Whether all selectable (non-disabled) items are selected

isMixed

ComputedRef<boolean>

Whether some but not all selectable items are selected

Methods

clear

() => void

Clear the entire registry

has

(id: ID) => boolean

Check if a ticket exists by ID

keys

() => ID[]

Get all registered IDs

browse

(value: unknown) => ID[] | undefined

Browse for an ID(s) by value

lookup

(index: number) => ID | undefined

lookup a ticket by index number

get

(id: ID) => Z | undefined

Get a ticket by ID

upsert

(id: ID, ticket?: Partial<Z>) => Z

Update or insert a ticket by ID

values

() => Z[]

Get all values of registered tickets

entries

() => [ID, Z][]

Get all entries of registered tickets

unregister

(id: ID) => void

Unregister an ticket by ID

reindex

() => void

Reset the index directory and update all tickets

seek

(direction?: "first" | "last", from?: number, predicate?: (ticket) => boolean) => Z | undefined

Seek for a ticket based on direction and optional predicate

on

(event: string, cb: RegistryEventCallback) => void

Listen for registry events

off

(event: string, cb: RegistryEventCallback) => void

Stop listening for registry events

emit

(event: string, data: unknown) => void

Emit an event with data

dispose

() => void

Clears the registry and removes all listeners

offboard

(ids: ID[]) => void

Offboard multiple tickets at once

batch

<R>(fn: () => R) => R

Execute operations in a batch, deferring cache invalidation and event emission until complete

reset

() => void

Clear all selected IDs and reindexes

selected

(id: ID) => boolean

Check if a ticket is selected by ID

mandate

() => void

Mandates selected ID based on "mandatory" Option

select

(ids: ID | ID[]) => void

Select one or more Tickets by ID

unselect

(ids: ID | ID[]) => void

Unselect one or more Tickets by ID

toggle

(ids: ID | ID[]) => void

Toggle one or more Tickets ON and OFF by ID

mix

(ids: ID | ID[]) => void

Set one or more Tickets to mixed/indeterminate state by ID

unmix

(ids: ID | ID[]) => void

Clear mixed/indeterminate state from one or more Tickets by ID

mixed

(id: ID) => boolean

Check if a ticket is in mixed/indeterminate state by ID

selectAll

() => void

Select all selectable (non-disabled) items

unselectAll

() => void

Unselect all items (respects mandatory option)

toggleAll

() => void

Toggle between all selected and none selected

onboard

(registrations: Partial<Z>[]) => E[]

Onboard multiple tickets at once

variation

(id: ID, fallback?: unknown) => unknown

Get the variation value of a feature, or a fallback if not set.

sync

(flags: FeaturesAdapterFlags) => void

Sync feature flags from an external source.

register

(registration?: Partial<Z>) => E

Register a feature (accepts input type, returns output type)

Was this page helpful?

ยฉ 2016-1970 Vuetify, LLC
Ctrl+/