Skip to main content

useFeatureFlagActive

The useFeatureFlagActive hook is a specialized wrapper around useFetch used to check if a specific feature flag is currently enabled for the user. It is ideal for simple "on/off" toggles and handles the evaluation logic through the personalization provider.

import { useFeatureFlagActive } from '@archibald/personalization';

const { data: isActive, isLoading } = useFeatureFlagActive(id, options);

Parameters

NameTypeRequiredDescription
idstring✔️The unique identifier of the feature flag.
optionsFeatureFlagCustom & FetchMinOptionsOptions for the request and data fetching.

id

The identifier used to look up the feature flag in the personalization provider (e.g., GrowthBook).

options

A combination of personalization-specific options and standard useFetch options. See useFetch for more information.

Return value

  • Type: FetchResult<boolean>
PropertyTypeDescription
databoolean | nullTrue if the feature flag is active, false otherwise.
isLoadingbooleanTrue if the flag status is being fetched.
isDonebooleanTrue if the fetch is complete.

Example

import { useFeatureFlagActive } from '@archibald/personalization';

function Header() {
const { data: isNewSearchActive } = useFeatureFlagActive('v2-search-enabled');

return (
<header>
<nav>
<a href="/">Home</a>
{isNewSearchActive ? <NewSearchBar /> : <OldSearchBar />}
</nav>
</header>
);
}