import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
useTagsEnabled
A hook that checks whether the tags feature is enabled in the application settings.
Source file: template/hooks/use-tags-enabled.ts
Overview
useTagsEnabled reads the tagsEnabled flag from the SettingsProvider context. Because the value is server-rendered and passed through React context, there is no loading delay or network request -- the result is available immediately on mount.
This hook answers the question "is the tags feature turned on?" which is controlled by the application configuration. It does not check whether any tags actually exist in the database (see useTagsExists for that).
Signature
function useTagsEnabled(): {
tagsEnabled: boolean;
loading: boolean;
error: Error | null;
}
Parameters
This hook takes no parameters.
Return Value
| Property | Type | Description |
|---|---|---|
tagsEnabled | boolean | true if the tags feature is enabled in application settings, false otherwise |
loading | boolean | Always false -- the value is available synchronously from context |
error | Error | null | Always null -- no asynchronous operation is performed |
Fallback Behavior
If the component is rendered outside of a SettingsProvider, the hook falls back to tagsEnabled: true (the provider's default fallback value).
Implementation Details
- The hook calls
useSettings()to access theSettingsProvidercontext. - It destructures the
tagsEnabledboolean from the context value. - It returns the value along with
loading: falseanderror: null, since the value comes from server-rendered context and involves no asynchronous fetching.
Usage Examples
Conditionally rendering tag chips on items
import { useTagsEnabled } from '@/hooks/use-tags-enabled';
function ItemDetail({ item }: { item: Item }) {
const { tagsEnabled } = useTagsEnabled();
return (
<article>
<h1>{item.title}</h1>
<p>{item.description}</p>
{tagsEnabled && item.tags.length > 0 && (
<div className="flex gap-2">
{item.tags.map((tag) => (
<TagChip key={tag.id} tag={tag} />
))}
</div>
)}
</article>
);
}
Hiding the tag filter sidebar
import { useTagsEnabled } from '@/hooks/use-tags-enabled';
function FilterSidebar() {
const { tagsEnabled } = useTagsEnabled();
return (
<aside>
<CategoryFilter />
{tagsEnabled && <TagFilter />}
<SortOptions />
</aside>
);
}
Combined with useTagsExists
import { useTagsEnabled } from '@/hooks/use-tags-enabled';
import { useTagsExists } from '@/hooks/use-tags-exists';
function TagCloud() {
const { tagsEnabled } = useTagsEnabled();
const { data } = useTagsExists();
// Only show tag cloud when feature is enabled AND tags exist
if (!tagsEnabled || !data?.exists) {
return null;
}
return <TagCloudWidget />;
}
Requirements
| Dependency | Purpose |
|---|---|
SettingsProvider | Provides the tagsEnabled value through React context |
Related Hooks
useTagsExists-- Checks whether tags exist in the databaseuseCategoriesEnabled-- Checks whether the categories feature is enableduseCompaniesEnabled-- Checks whether the companies feature is enableduseSurveysEnabled-- Checks whether the surveys feature is enabled