RocketChat/Rocket.Chat

View on GitHub
packages/ui-contexts/src/hooks/useSetting.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { ISetting, SettingValue } from '@rocket.chat/core-typings';

import { useSettingStructure } from './useSettingStructure';

export function useSetting<TValue extends SettingValue>(settingId: ISetting['_id']): TValue | undefined;
export function useSetting<TValue extends SettingValue>(settingId: ISetting['_id'], fallbackValue: TValue): TValue;
export function useSetting<TValue extends SettingValue>(settingId: ISetting['_id'], fallbackValue?: TValue): TValue | undefined {
    const setting = useSettingStructure(settingId);
    return (setting?.value as TValue | undefined) ?? fallbackValue;
}