fannypack-v5
Version:
An accessible, composable, and friendly React UI Kit
36 lines (30 loc) • 970 B
JavaScript
import { useCallback } from 'react';
import '../Provider/ThemeContext.js';
import 'classnames';
import 'emotion';
import '@emotion/core';
import 'emotion-theming';
import '@emotion/styled';
import { useTheme } from './useTheme.js';
function useLocalStorage() {
var _useTheme = useTheme(),
theme = _useTheme.theme;
var isEnabled = theme.modes.enableLocalStorage;
var get = useCallback(function (key) {
if (!isEnabled) return;
if (typeof window !== 'undefined') {
return window.localStorage.getItem(theme.modes.localStoragePrefix + "." + key);
}
}, [isEnabled, theme.modes.localStoragePrefix]);
var set = useCallback(function (key, value) {
if (!isEnabled) return;
if (typeof window !== 'undefined') {
return window.localStorage.setItem(theme.modes.localStoragePrefix + "." + key, value);
}
}, [isEnabled, theme.modes.localStoragePrefix]);
return {
get: get,
set: set
};
}
export { useLocalStorage };