UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

25 lines (24 loc) 1.17 kB
'use client'; import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import * as React from 'react'; import useLocalStorageState from "../useLocalStorageState/index.js"; import { usePreferences } from "./PreferencesProvider.js"; var variantPrefPrefix = '_docs_variant_pref'; var transformPref = '_docs_transform_pref'; export function usePreference(type, name) { var initializer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var key = React.useMemo(function () { if (!Array.isArray(name)) { return name; } if (name.length <= 1) { return null; // Don't use localStorage for single variants - no choice to remember } return _toConsumableArray(name).sort().join(':'); }, [name]); var preferences = usePreferences(); var defaultPrefix = type === 'variant' ? variantPrefPrefix : transformPref; var prefix = preferences != null && preferences.prefix ? "".concat(preferences == null ? void 0 : preferences.prefix, "_").concat(type) : defaultPrefix; var storageKey = key ? "".concat(prefix, ":").concat(key) : null; return useLocalStorageState(storageKey, initializer); }